Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to assign a foreign key in a table
Posted
Comments
[no name] 28-Oct-11 7:55am    
Please, don't overload us with all this information.

It's not at all clear what you mean by 'assigning' a foreign key. Do you want to set a foreign key constrain for a table or do you have problems when inserting rows into a table with a foreign key constraint?

This[^] explain how to create a foreign key constraint.
 
Share this answer
 
Comments
Uday P.Singh 28-Oct-11 8:03am    
my 5!
André Kraak 28-Oct-11 8:33am    
Thank you.
use this query..

create table tblname(uid int foreign key references dbo.sometable(primarykeycolumn))

hope it helps...
 
Share this answer
 
create table tblname(deptid int,dept varchar(50),uid int foreign key references dbo.prevtable(uid))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900