O'Reilly logo

SQL: Visual QuickStart Guide by Chris Fehily

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required