Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 trouble with foreign keys

Author  Topic 

ghostfly
Starting Member

6 Posts

Posted - 2011-02-12 : 20:50:52
Trying to make a foreign key and I keep getting errors

Msg 1769, Level 16, State 1, Line 6
Foreign key 'DepartID' references invalid column 'DepartID' in referencing table 'EmployeesF'.
Msg 1750, Level 16, State 0, Line 6
Could not create constraint. See previous errors.

Alter Table EmployeesF

Add foreign Key (DepartmentID) references Departments(DepartmentID)


my tables

Create Table Departments
(
DepartmentID int Not Null,
DepartmentName varchar(255),
LocationID int,
Primary Key(DepartmentID),
Foreign Key(LocationID) references Locations(LocationID)

)

Create Table EmployeesF
(
EmployeeID int Not Null,
FirstName varchar(255),
LastName varchar(255),
EMail varchar(255),
Salary int,
PhoneNumber varchar(15),
HireDate date,
Primary Key(EmployeeID),
Foreign Key(ManagerID) references Employees(EmployeeID)
)

CREATE TABLE Locations
(
LocationID int NOT NULL,
PostalCode int ,
City varchar(255),
StateProvince varchar(255),
Country varchar(255),
PRIMARY KEY (LocationID),

)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-12 : 22:21:57
DepartmentID should be a column in table EmployeesF



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ghostfly
Starting Member

6 Posts

Posted - 2011-02-13 : 08:40:56
TYMV you helped me greatly
Go to Top of Page
   

- Advertisement -