Database Reference
In-Depth Information
In SQL, you use the CHECK clause to enforce legal-values integrity. For example, to ensure that the only
legal values for credit limits are $5,000, $7,500, $10,000, or $15,000, include the following CHECK clause in a
CREATE TABLE or ALTER TABLE command:
CHECK (CreditLimit IN (5000, 7500, 10000, 15000))
The general form of the CHECK clause is the word CHECK followed by a condition. In the previous
CHECK clause, the credit limit must be in the set consisting of 5000, 7500, 10000, or 15000. The DBMS will
automatically reject any update to the database that violates the condition in the CHECK clause.
In Access, you can restrict the legal values accepted by a field by entering an appropriate validation rule
that data entered in the field must follow. Figure 4-21 shows the validation rule that restricts entries in the
CreditLimit field to 5000, 7500, 10000, and 15000. Along with the validation rule, you usually enter valida-
tion text to inform the user of the reason for the rejection when the user attempts to enter data that violates
the rule.
136
CreditLimit ield
is selected
Validation rule for the
CreditLimit ield
Validation text for the
CreditLimit ield
FIGURE 4-21
Specifying a validation rule in Access
Search WWH ::




Custom Search