Primary Key vs Unique Constraint
A primary key is a defined field or set of fields that a data architect identifies as the selected way to relate to a table. Once defined, all foreign keys that relate to the table must do so with the primary key. Only one primary key can be defined for a table.A primary key automatically has a unique constraint applied to it. As only one primary key can be defined in a table, subsequent definitions to prevent duplicates in tables are defined with a unique constraint.Example
A CUSTOMER table has an ID as a primary key and NAME, MOBILE_PHONE as a unique constraint. Foreign keys relate to the table using ID. It is impossible to enter someone with the same name and mobile phone number into the table as the database will throw an error.Overview: Unique Constraint | ||
Type | ||
Definition | A field or set of fields that must be unique for each row in a table. | |
Value | Prevents data duplication. | |
Related Concepts |