1.

What is the primary key and foreign key?  

Answer»

The PRIMARY key is the single column or combination of the column which uniquely distinguishes individual rows in the table. It MUST be unique but can not have  NULL values which make it different then UNIQUE KEY. A table can have only a single primary key and contain a single column or combination of columns called a composite key.  The foreign key in the table is actually the to the primary key of another table. Please find below the list of differences between two Keys which look SIMILAR in nature :

  1. Primary Key can not have NULL values while foreign key can have NULL values.
  2. Be default primary key creates CLUSTERED Index on the table which physically sorts out data based on key while there is no index created on the foreign key. We need to explicitly create indexes on the foreign key.
  3. We can have a single primary key in the table but we can have multiple foreign keys in the table.



Discussion

No Comment Found