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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Alter Table

Author  Topic 

rn5a
Starting Member

25 Posts

Posted - 2008-10-31 : 05:04:56
I have 2 tables - Table1 & Table2. There is a column named Col1 in both the tables. Col1 is the PRIMARY KEY in Table1. I want Col1 in Table2 to be the FOREIGN KEY of this PRIMARY KEY column.

How do I make Col1 in Table2 the FOREIGN KEY using the ALTER TABLE statement?

Thanks,

Ron

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-31 : 05:30:10

alter table table2
add constraint fk foreign key(col1) references table1(col1)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -