Sql Server Keys Candidatekey,Primarykey,Foreignkey,self-referencing foreign key

One of my regular blog reader Mr.Jithin requested me to explain about the different types of keys in sql server. Let’s come have a look into this topic.

The different types of Keys in sql server are,

  • A candidate key acts as a unique key. A unique key can be a Primary key. A candidate key can be a single column or combination of columns. Multiple candidate keys are allowed in a table.
  • Primary Key
    • To uniquely identify a row, Primary key is used.
    • A table allows only one Primary key
    • A Primary key can be a single column or combination of columns.
  • Foreign Key
    • A foreign key in a table is a key which refer another table’s primary key . A primary key can be referred by multiple foreign keys from other tables. It is not required for a primary key to be the reference of any foreign keys. The interesting part is that a foreign key can refer back to the same table but to a different column. This kind of foreign key is known as “self-referencing foreign key”.
print

2 thoughts on “Sql Server Keys Candidatekey,Primarykey,Foreignkey,self-referencing foreign key

  1. Author’s gravatar

    Nice article, I also did some analysis and created my blog.
    Have a look at the below link –

    http://vsstack.blogspot.in/p/keys-in-sql-server.html

  2. Author’s gravatar

    Hi,

    Today I just read your blog it was really nice but I have one confusion. You said in your article that a Candidate Key can be a Unique Key. But as per definition of Unique Key, Unique key can contain multiple null . So how Candidate Key is Unique Key?

Leave a Reply

Your email address will not be published. Required fields are marked *


+ 6 = eleven