Corrective single-record constraints

Previous Next

To define a corrective single-record constraint, write an UPDATE... SET... WHERE... statement that corrects data in one or more of the record's columns. This type of constraint performs a correction on one single record. The syntax of a corrective single-record constraint is:

UPDATE   table
SET      column = correction
WHERE    condition

Example

Suppose that the Travel Agency system requires default values for return dates of a scheduled tour. This can be handled as follows: if the user leaves the return_date field empty, a date one week later than the (mandatory) start_date is automatically inserted. The following constraint takes care of this:

UPDATE    schedtour
SET       return_date = start_date + 7
WHERE     return_date IS NULL

OLD()

You can use the OLD() function, or you can set transition properties for the constraint, or both, in which case you turn the constraint into a transitional constraint.

 

See also

Single-record constraints

Restrictive single-record constraints

Restrictive multi-record constraints

Corrective multi-record constraints