Adding new foreign key column to existing table

Hello
I am trying to create a new table with a primary key and another correseponding column in another table as the foreign key and whilst I am successfully able to do that, there is an indication in sql server that there is an error some where
Screenshot 1
I have attached a screen shot and I am hoping someone could help with some clarity.

Probably because the intellisense feature that inserts those red squigglies doesn't recognize the new column. Try running the alter table statement in a separate query window. Even then it may complain if the intellisense cache has not been updated.

You can use the Query -> Parse menu in SSMS to check for syntax errors, but in this case it is not a syntax error.

Ctrl + Shift + R will refresh the intellisense cache and the indication will dissapear.

1 Like

You can't add the column and update the column in the same batch. You need to separate the ALTER from the UPDATE with a GO.

That won't solve the problem with the red lines - because the column doesn't exist yet.