Explain the difference between a primary key and a unique key in a relational database management system (RDBMS).

1 Answers
Answered by suresh

Difference Between Primary Key and Unique Key in RDBMS

Difference Between Primary Key and Unique Key in RDBMS

In a relational database management system (RDBMS), the primary key and unique key are both constraints that enforce the uniqueness of data in a table. However, there are key differences between the two:

Primary Key:

  • A primary key uniquely identifies each record in a table.
  • There can be only one primary key in a table.
  • Primary key columns do not allow NULL values.
  • By default, primary key columns are indexed for faster data retrieval.

Unique Key:

  • A unique key ensures that all values in a column are unique.
  • Multiple unique keys can exist in a table.
  • Unique key columns can have NULL values, but only one NULL is allowed.
  • Unique key constraints create a unique index automatically.

It is important to choose the appropriate key constraint based on the data requirements and relationships within the database schema.

Answer for Question: Explain the difference between a primary key and a unique key in a relational database management system (RDBMS).