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
 Create FKs in the management console

Author  Topic 

stevescottwork
Starting Member

1 Post

Posted - 2009-04-20 : 12:09:25
Ive got a working DB structure with primary keys, etc...but I dont have any FK linking (and there really should be some :)

How do I go about linking those so in the management console I see the silver key on that column?

Any info would be appreciated,
Thanks
Steve

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-04-20 : 12:19:36
In Management Studio, expand the table, right-click on "Keys" and choose "New Foreign Key". OR, use ALTER TABLE:

ALTER TABLE ChildTable ADD CONSTRAINT FK_ChildTable_ParentTable FOREIGN KEY (ParentID) REFERENCES ParentTable (ParentID)

Change your table and column names where appropriate. See Books Online if you need more details.
Go to Top of Page
   

- Advertisement -