1 Answers
Difference between Primary Key and Unique Key in DBMS
In a database management system (DBMS), both primary key and unique key are used to uniquely identify a record in a table. However, there are key differences between these two:
Primary Key:
- Primary key is a column (or a set of columns) that uniquely identifies each record in a table.
- It must have a unique value for each record and cannot contain null values.
- There can be only one primary key in a table.
- Primary key automatically creates a clustered index on the table to provide fast data retrieval.
Unique Key:
- Unique key is a column (or a set of columns) that ensures the values in it are unique for every record in the table.
- It allows null values, but each non-null value must be unique.
- There can be multiple unique keys in a table.
- Unique key enforces the uniqueness constraint on the table but does not create a clustered index.
Overall, primary key is used to uniquely identify each record, enforce entity integrity, and provide fast data retrieval, while unique key ensures data integrity by maintaining uniqueness without the requirement of a clustered index.
Please login or Register to submit your answer