Jump to content

Check constraint

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by LegitimateAndEvenCompelling (talk | contribs) at 02:22, 31 August 2006 (grammar). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Template:Linkless-date A check constraint is a rule that defines valid data when adding or updating an entry in a database. A check constraint is applied to a column in the database. The constraint must be a Boolean expression.

For example, in a database containing products, you could add a check constraint such that the price of a product and quantity of a product is either zero or a positive value:

PRICE >= 0

QUANTITY >= 0

If these constraints were not in place, it would be possible to have a negative price (-$30) or quantity (-3 items).

Check constraints are used to ensure the validity of data in a database, i.e., provide data integrity. If they are used at the database level, applications that use the database will not be able to add invalid data or modify valid data so they become invalid, even if the application itself accepts invalid data.