Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere 10 - Context-Sensitive Help » SQL Anywhere Plug-in Help » Introduction to SQL Anywhere property sheets

Check Constraint property sheet: General tab Next Page

Check Constraint property sheet: Definition tab


The Definition tab of the Check Constraint property sheet has the following components:

This check constraint has the following definition    Provides a place for you to type the check constraint. A column check constraint is used to ensure that no inappropriate values are entered into any column of the specified type, while a table check constraint ensures that no row in a table violates the constraint.

Column check constraint example

You can enforce a particular formatting requirement. For example, if a table has a column for phone numbers you may want to ensure that users enter them all in the same manner. For North American phone numbers, you could use a constraint such as:

ALTER TABLE Customers
ALTER Phone
CHECK ( Phone LIKE '(___) ___-____' );

Once this CHECK condition is in place, if you attempt to set a Phone value to 9835, for example, the change is not allowed.

Table check constraint example

For example, you can add a constraint on the Employees table to ensure that the TerminationDate is always later than, or equal to, the StartDate:

ALTER TABLE Employees
 ADD CONSTRAINT valid_term_date
 CHECK(TerminationDate >= StartDate);
See also