Specifying a Primary Key with PRIMARY KEY

I described primary keys in “Primary Keys” in Chapter 2, but I’ll review the basics here:

  • A primary key uniquely identifies each row in a table.

  • No two rows can have the same primary-key value.

  • Primary keys don’t allow nulls.

  • Each table has exactly one primary key.

  • A primary key is a column or a set of columns. A simple primary key comprises a single column; a composite primary key comprises multiple columns.

  • In a composite key, values can be duplicated within one column, but each combination of values from all the key’s columns must be unique.

  • A table can have more than one combination of columns that uniquely identify its rows; each combination is a candidate key. The database designer picks one of the candidate ...

Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.