If I am using the following SQL command in SQL Server 2008 to update a table with a foreign key constraint:
ALTER TABLE Employees
ADD FOREIGN KEY (UserID)
REFERENCES ActiveDirectories(id)
UserID
being my FK column in the Employees
table. I'm trying to reference the UserID
in my ActiveDirectories
table. I receive this error:
Foreign key 'UserID' references invalid column 'UserID' in referencing
table 'Employees'.
Best Answer
Error indicates that there is no UserID column in your Employees table. Try adding the column first and then re-run the statement.