Creating a check constraint specifies a condition that any value must pass before it is inserted into the table.
A check constraint specifies a condition that any value must pass before it is inserted into the table. You can can create a check constraint at the table or column level. Column-level check constraints reference a single column. Table-level check
constraints apply to the entire table.
- Select , then choose one of the following:
- Select a table for the new check constraint.
- Select Properties.
- From the Table Properties window, select .
You see the Add Check Constraint wizard.
- Enter a name for the check constraint.
- Enter an expression that defines the constraint.
For example,
salary > 0. The comparable command line syntax using
alter tableis:
alter table sample.dbo.employee
add constraint test_const
CHECK (salary > 0)
- (Optional) Click Summary to verify the check constraint expression.