Visual Database Tools
Attaching a New Check Constraint to a Table or Column
Attach a
To attach a new check constraint
- In your database diagram, right-click the table that will contain the constraint, then select Constraints from the shortcut menu.
-or-
Open the Table Designer for the table that will contain the constraint, right-click in the Table Designer, and choose Constraints from the shortcut menu.
- Choose New. The Selected constraint box displays the system-assigned name of the new constraint. System-assigned names begin with "CK_" followed by the table name.
- In the Constraint expression box, type the SQL expressions for the check constraint. For example, to limit the entries in the
state
column of theauthors
table to New York, type:state = 'NY'
Or, to require entries in the
zip
column to be 5 digits, type:zip LIKE '[0-9][0-9][0-9][0-9][0-9]'
Note Make sure to enclose any non-numeric constraint values in single quotation marks ('). For additional details, see Defining a Check Constraint Expression.
- If you want to give the constraint a different name, type the name in the Constraint name box.
- Use the check boxes to control when the constraint is enforced:
- To test the constraint on existing data before creating the constraint, check Check existing data on creation.
- To enforce the constraint whenever a replication operation occurs on this table, check Enforce constraint for replication.
- To enforce the constraint whenever a row of this table is inserted or updated, check Enforce constraint for INSERTs and UPDATEs.
- To test the constraint on existing data before creating the constraint, check Check existing data on creation.
See Also
Check Constraints | Constraints | Deleting a Check Constraint | Disabling a Check Constraint for Replication