Adding check to an existing table.

Posted by Abhisek under Sql Server category on | Views : 1631
When a check constraint is added to an existing table, the check constraint can apply to either,
Existing data
To new data only

By default the check constraints applies to new data as well as existing data,
ALTER TABLE <table_name> ADD CONSTRAINTS<constraint_name> CHECK(condition)

Adding to new data only:

ALTER TABLE <table_name> with no check ADD CONSTRAINTS<constraint_name> CHECK(condition)

You will be careful when adding a constraint without checking the existing data, because this bypasses the controls in Microsoft SQL Server 2000 that enforces the integrity rules for the table.

Comments or Responses

Login to post response