July 27, 2012 at 2:12 am
I have a Table T1 with columns Col1, Col2, Col3, Col4, Col5 having primary key on columns Col1, Col2, Col3. And I have another table T2 with columns C1, C2, C3, C4, C5, C6, C7, C8. Now the column C1 of table T2 should be referenced by Col1 of table T1. Is it possible to define foreign key on C1 column of table T2 with reference to Col1 column of table T1 ?
July 27, 2012 at 2:38 am
If you have a UNIQUE KEY constraint on the column Col1 of table T1, then its possible to define a FOREIGN KEY as you have mentioned
But, if the column is not UNIQUE, then its not possible
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 27, 2012 at 7:06 am
I am testing it with implementing the logic using triggers. I hope it will work fine.
July 27, 2012 at 12:41 pm
Kingston Dhasian (7/27/2012)
If you have a UNIQUE KEY constraint on the column Col1 of table T1, then its possible to define a FOREIGN KEY as you have mentionedBut, if the column is not UNIQUE, then its not possible
+1
Basic criteria to define a foreign key is that it either references PK or if referenced key is not PK than it has to be unique.
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply