| |
A unique constraint is a field or set of fields that must be unique for each row in a table. Data architects define unique constraints so that databases will automatically enforce the logical validity of data. Where a unique constraint is defined, the database will not permit duplicate values for the field or set of fields in the constraint definition.
Primary Key vs Unique ConstraintA 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.
ExampleA 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.
IT Skills
This is the complete list of articles we have written about it skills.
If you enjoyed this page, please consider bookmarking Simplicable.
© 2010-2023 Simplicable. All Rights Reserved. Reproduction of materials found on this site, in any form, without explicit permission is prohibited.
View credits & copyrights or citation information for this page.
|