Foreign Key question

  • 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 ?

  • 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


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • I am testing it with implementing the logic using triggers. I hope it will work fine.

  • 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 mentioned

    But, 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


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    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