Adding a Check Constraint with CHECK

So far, the only restrictions on an inserted value are that it have the proper data type, size, and range for its column. You can use check constraints to further limit the values that a column (or set of columns) accepts. Check constraints commonly are used to check the following:

  • Minimum or maximum values. Prevent sales of fewer than zero items, for example.

  • Specific values. Permit only 'biology', 'chemistry', or 'physics' in the column science, for example.

  • A range of values. Make sure that an author’s royalty rate is between 2 percent and 20 percent, for example.

A check constraint resembles a foreign-key constraint in that both control values placed in a column (see “Specifying a Foreign Key with FOREIGN ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.