What is the difference between a PRIMARY KEY and a UNIQUE KEY?

Category: SQLWhat is the difference between a PRIMARY KEY and a UNIQUE KEY?
Editor">Editor Staff asked 2 years ago

What is the difference between a PRIMARY KEY and a UNIQUE KEY?

  1. Primary key can store null value, whereas a unique key cannot store null value.
  2. We can have only one primary key in a table while we can have multiple unique keys
  3. Primary key cannot be a date variable whereas unique key can be
  4. None of these
1 Answers
Editor">Editor Staff answered 2 years ago

Answer:
2. We can have only one primary key in a table while we can have multiple unique keys
Explanation:
The primary key is a single or combination of the field that identifies each record in a table uniquely. It cannot take a NULL value. A table can have only one primary key. Also, we can create a date variable as a primary key in a table.
Unique key also determines each row of the table uniquely, but it can take null value into. A table can have more than one unique key. We cannot create a date variable as a unique key in a table.