1 Answers
Differences between Primary Key and Unique Key in RDBMS
In a Relational Database Management System (RDBMS), both primary key and unique key are used to enforce uniqueness of data. However, there are key differences between them:
Primary Key
- Primary key is a column (or a set of columns) that uniquely identifies each record in a table.
- A table can have only one primary key.
- Primary key does not allow null values.
- Primary key automatically creates an index on the column(s) it is defined on.
- Primary key is used to establish relationships between tables.
Unique Key
- Unique key is a column (or a set of columns) that ensures the values in the column(s) are unique.
- A table can have multiple unique keys.
- Unique key allows null values, except when the column(s) are part of a composite unique key.
- Unique key creates a unique constraint that ensures data integrity.
- Unique key is used to enforce data uniqueness but not as a reference for foreign key relationships.
Overall, the primary key is used to uniquely identify records and establish relationships, while unique key is used to ensure data integrity and enforce uniqueness constraints in a table.
Please login or Register to submit your answer