What is the differences between Keys in SQL

Total Post:26

 999  View(s)
Rate this:

Please give me a exact difference between among different types  of keys in sql such as Primary Key,Foriegn Key etc.
Thank you.
  1. Post:135

    Re: What is the differences between Keys in SQL

    Hi Simond,

    Their is basically following keys in SQL:

    1. Candidate Key
    2. Primary Key
    3. Foriegn Key
    4. Alternate Key
    5. Composite Key

    Here, we are explaining a simpler way to each key :

    Candidate Key: 

    Candidate keys are those keys which is candidate for primary key of a table. In simpler we can understand that such type of keys which full fill all the requirements of primary key which is not null and have unique records is a candidate for primary key. So thus type of key is known as candidate key. Every table must have at least one candidate key .

    Primary Key:

    Such type of candidate key which is chosen as a primary key for table is known as primary key. Primary keys are used to identify tables. There is only one primary key per table

    Foreign Key:

    Foreign key are those keys which is used to define relationship between two tables. When we want to implement relationship between two tables then we use concept of foreign key. It is also known as referential integrity.

    Alternate Key:

    If any table have more than one candidate key, then after choosing primary key from those candidate key, rest of candidate keys are known as an alternate key of  that table

    Composite Key:

    When we create keys on more than one column then that key is known as composite key. I have a table Employee which has two columns Empid and EmpReferenceNo and we make primary key on these two column. Then this key is known as composite key:

    For More details with example ,Please click HERE

      Modified On Feb-28-2016 11:49:17 PM