Primary key

An attribute or set of attributes in a database that uniquely identifies each record in a table. A primary key allows no duplicate values and cannot be null. A primary key is a column (or concatenation of columns) that comprises unique values and is designated by the user or the database system. However not all fields of unique values are primary keys, for example, a table that contains unique values in both a CustomerID field and a Social Security number field may have only the CustomerID field designated as the primary key.

Defining primary keys
Primary keys are defined in the ANSI SQL Standard, through the PRIMARY KEY constraint. The syntax to add such a constraint to an existing table is defined in SQL:2003 as follows:

The primary key can also be specified directly during table creation. In the SQL Standard, primary keys may consist of one or multiple columns. Each column participating in the primary key is implicitly defined as NOT NULL. Note that some DBMS require that primary key columns are explicitly marked as being NOT NULL.

If the primary key consists only of a single column, the column can be marked as such using the following syntax: