What is the difference between a primary key and a unique key

0

The primary key and unique key both are essential constraints of the SQL. The main difference among them is that the primary key identifies each record in the table. In contrast, the unique key prevents duplicate entries in a column except for a NULL value. The following comparison chart explains it more clearly:


Primary Key
The primary key act as a unique identifier for each record in the table.
We cannot store NULL values in the primary key column.
We cannot change or delete the primary key column values.

Unique Key
The unique key is also a unique identifier for records when the primary key is not present in the table.
We can store NULL value in the unique key column, but only one NULL is allowed.
We can modify the unique key column values.

Sql
asked Apr 14, 2023 at 21:40
Sign in to add a comment

0 Answers

0
📝 No answers yet!

Be the first to answer this interview question.

Your Answer

Sign in to post your answer and help the community.