locked
Foreign Key on a column which is not Primary Key of the table RRS feed

  • Question

  • Hi,

    Please assits me on this

    Can we create Foreign Key on the column which is not Primary Key of the table? Is unique constraint sufficient for this?

    Thanks in advance.

    Friday, August 1, 2014 3:37 PM

Answers

  • Yes, you can create a foreign key which references a column  with a unique constraint on it

    --Prashanth



    Friday, August 1, 2014 3:41 PM
  • Check this link http://msdn.microsoft.com/en-us/library/ms189049.aspx

    Limitations and Restrictions

    • A foreign key constraint does not have to be linked only to a primary key constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table.


    Regards, Ashwin Menon My Blog - http:\\sqllearnings.com

    • Proposed as answer by Itz Shailesh Friday, August 1, 2014 3:51 PM
    • Marked as answer by Charlie Liao Monday, August 4, 2014 9:44 AM
    Friday, August 1, 2014 3:48 PM

All replies

  • Yes, you can create a foreign key which references a column  with a unique constraint on it

    --Prashanth



    Friday, August 1, 2014 3:41 PM
  • Check this link http://msdn.microsoft.com/en-us/library/ms189049.aspx

    Limitations and Restrictions

    • A foreign key constraint does not have to be linked only to a primary key constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table.


    Regards, Ashwin Menon My Blog - http:\\sqllearnings.com

    • Proposed as answer by Itz Shailesh Friday, August 1, 2014 3:51 PM
    • Marked as answer by Charlie Liao Monday, August 4, 2014 9:44 AM
    Friday, August 1, 2014 3:48 PM
  • YES!  WHY ARE YOU SO LAZY YOU DID READ ANY BOOK ON SQL OR GOOGLE IT ??? 


    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in Sets / Trees and Hierarchies in SQL

    Friday, August 1, 2014 10:06 PM