Constraints
Week 2: Articles
Constraint Types
Learning Outcomes
- Learn how to create, modify, and remove constraints.
- Learn how constraints work.
Lesson Materials
There are five types of constraints that you may assign to tables. They are:
NOT NULL
ConstraintNOT NULL
constraints let you make a column mandatory when inserting or updating a row in the table.CHECK
ConstraintCHECK
constraints let you verify the contents that you insert or update in a column based on literal, regular expression, or other column(s) value comparisons.UNIQUE
ConstraintUNIQUE
constraints let you make a column or set of columns unique values within all rows of a table and they build an implicit index to enforce the constraint.PRIMARY KEY
ConstraintPRIMARY KEY
constraints let you identify a column or set of columns as the primary key of a table. You typically assign a surrogate or sequence generated single column as a primary key column; or you assign a collection of descriptive columns that are unique as a natural key for the subject of the table.FOREIGN KEY
ConstraintFOREIGN KEY
constraints let you identify a column or set of columns as a copy of a primary key from another table or from a copy of the same table where you define the foreign key.