limited time offer

What Is The Main Difference Between Primary Key, Unique Key, And Foreign Key?

Below are the difference between Primary Key, Unique Key and Foreign Key

Parameters Primary Key Unique Key Foreign Key
Basic A primary key is a column of table which uniquely identifies each tuple (row) in that table. Primary key enforces integrity constraints to the table. Unique key constraints also identifies an individual tuple uniquely in a relation or table. A table can have more than one unique key unlike primary key. Foreign key is a field in the table that is primary key in another table.
Null Value Acceptance Cannot accept null values. Can accept one null value. Accept multiple null values.
Number of keys that can be defined in a table Only one primary key More than one unique key We can have more than one foreign key in a table.
Index Create cluster index Create non-cluster index Do not automatically create an index clustered or non-clustered. You must manually create an index of foreign key.
Support Auto-increment of Value Supported Not supported Not supported
Restriction on delete We can't delete primary key value from the parent table which is used as a foreign key in child table. To delete we first need to delete that primary key value from the child table. Unique Constraint can not be related with another table's as a Foreign Key. In SQL Server, Unique key can be made foreign key into another table. We can delete the foreign key value from the child table even though that refers to the primary key of the parent table.