Add Foreign Key
-
Posted on July 26, 2009 by Derek Dieter
-
3
To Add a foreign key to a column in an existing table, use ALTER TABLE ADD CONSTRAINT
[cc lang=”sql”]
ALTER TABLE dbo.President_Lookup
ADD CONSTRAINT fk_PresidentID
FOREIGN KEY (PresidentID)
REFERENCES dbo.Presidents (PresidentID)
[/cc]
- Comments (RSS)
- Trackback
- Permalink
Hi Derek,
Firstly, I just wish to thank you for all your effort to explain us every one of these details about SQL Server. I just have only one question to ask:
Is there any reason why you omitted DML’s issues or topics regarding that?. I mean by not apparing a “DML” above; perhaps it might be silly, I know, but I wanted to clear any doubts about this, or rather, can you inform us where we could find these issues?.
Thanks in advance.
Regards.
I have 1 query.
I have 2 tables, one is master and another is normal table.
the primary key of one table is used in 2nd table…
bt I dont know, how I can set that key will foreign..????
please send mi feedback on my email…
or give mi an example code for setting foreign key…