Can someone please explain the difference between UNIQUE and PRIMARY KEY clauses? I don’t know how these clauses specify the uniqueness in different ways:slightly_smiling_face:

The difference is really one of purpose.

UNIQUE just tells SQL that this column cannot contain duplicate values.

PRIMARY KEY, however, tells SQL that the designated column(s) are the unique and and individual identifier for the record (row). Thus, PRIMARY KEY implies UNIQUE.

Primary key column(s) also cannot contain NULL values whereas you can have NULL values in a column which is simply unique.


Thanks for the clear explanation :slight_smile:

No worries.

It took me a while to get to that post. The difference is subtle, I think, and it can seem a little bit like there’s a difference for the sake of there being a difference, so I wanted to try and get it as clear as possible.

Still not convinced there isn’t a better explanation of the differences…


This is generally not true, especially in the context of the Codecademy course.

Codecademy uses SQLite in the course. SQLite, PostgreSQL, MySQL, Oracle allow multiple NULL values in the UNIQUE columns. It’s rather unpopular to allow only a single NULL value, the only example that comes to my mind is MS SQL.


That might’ve been what I was thinking of.

I’ll amend the answer. :slight_smile:


Thank you very much :slight_smile:


Thanks for the correction and help :slight_smile: