Understanding Constraints

Constraints allow you to define rules for values allowed in columns (Table 10.1). Your DBMS uses these rules to enforce the integrity of the database automatically. Constraints come in two flavors:

  • A column constraint is part of a column definition and imposes a condition on that column only.

  • A table constraint is declared independently of a column definition and can impose a condition on more than one column in a table. You must use a table constraint to include more than one column in a constraint.

You can specify some constraints as either column or table constraints, depending on the context in which they’re used. If a primary key contains one column, for example, you can define it as a column constraint or as a ...

Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.