A primary key has three properties:
- The key is unique across all rows of a table.
- The key (or no components of a composite key) are
NULL
.
- There is only one per table.
In general, primary keys are used for foreign key relationships. They are typically integers, because that is somewhat more efficient for indexing.
Other columns or combinations of columns can be unique and non-NULL
. Those are candidate primary keys. However, a table has only one primary key.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…