Difference between Primary Key and Unique key

Computer EngineeringComputer NetworkMCA

Both Primary Key and Unique key are used to get records from tables. These keys are also used to create relationship between tables. Primary Key and Unique key both are used to identify records uniquely in a table. A table can have only one primary key whereas unique keys can be multiple in a single table or relation.

Following are the important differences between Primary Key and Unique key.

Sr. No.KeyPrimary KeyUnique key
1DefinitionPrimary Key is used to identify all the records in a relation uniquely.Unique key is also used to identify a records uniquely.
2NULLPrimary key can not have null value.Unique key can accept one null value.
3Count WisePrimary key can be only one per table.Unique key can be multiple in a table.
4IndexPrimary key creats clustered index.Unique key creates non-clustered index.
raja
Published on 27-Nov-2019 11:55:18
Advertisements