sql - Please explain the syntax the SQLServer uses to create a check constraint -
when right click on default constraint , ask sql server create create script it, generates following code:
alter table [dbo].[tbleventturnjudgestartvalues] nocheck add constraint [tbleventturnjudgestartvalues_executiontoggle] check (([executiontoggle]=(1) or [executiontoggle]=(0) or [executiontoggle]=(-1))) go alter table [dbo].[tbleventturnjudgestartvalues] check constraint [tbleventturnjudgestartvalues_executiontoggle]
for record, understand first alter statement not understand the second alter statement does. tried google "check constraint" phrase got hits on add constraint syntax.
thanks.
seth
update
joe answer. found link helps.
http://blog.sqlauthority.com/2009/11/12/sql-server-disable-check-constraint-enable-check-constraint/
i did not know enable , disable constraints. cool!
seth
the first statement creates constraint, since created nocheck, existing data not validated @ time of creation.
the second statement turns constraint on , technically redundant.
personally, i'd prefer second statement written with check
option, validate existing data against constraint , prevent constraint becoming untrusted.
alter table [dbo].[tbleventturnjudgestartvalues] check check constraint [tbleventturnjudgestartvalues_executiontoggle]
Comments
Post a Comment