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

A column in a table (an attribute in an entity) is called a PRIMARY KEY if it uniquely identifies a specific row in a table of multiple rows. A UNIQUE key is a constraint applied on the data of a column. Technically, both are constraints that a column data must satisfy to be added in a table.

  • A UNIQUE key means that the column must not contain any duplicate values, meaning all the values in the column must be UNIQUE.
  • A column with UNIQUE key can accept NULL as a valid value (for only once in the column)
  • A PRIMARY key means that the column must be UNIQUE and no NULL values are allowed (even once)

SQL Posted Mar 19, 2021

You can now show your support. 😊

We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept