I have some auto-generated T-SQL, which is probably valid, but I don't really understand.
ALTER TABLE [dbo].[MyTable]
WITH CHECK
CHECK CONSTRAINT [My_FORIEGN_KEY];
I know what a foreign key constraint is, but what's the CHECK CHECK
?
constraintsql servert-sql
I have some auto-generated T-SQL, which is probably valid, but I don't really understand.
ALTER TABLE [dbo].[MyTable]
WITH CHECK
CHECK CONSTRAINT [My_FORIEGN_KEY];
I know what a foreign key constraint is, but what's the CHECK CHECK
?
Best Answer
The MSDN documentattion page about
ALTER TABLE
explains these:ALTER TABLE
: modify the table's structure(and some of the possible actions/modifications are):
CHECK CONSTRAINT ..
: enable the constraintNOCHECK CONSTRAINT ..
: disable the constraintThere are also additional, optional steps to do while creating/enabling/disabling a constraint:
WITH CHECK
: check the constraint as wellWITH NOCHECK
: do not check the constraintIn their words:
Test in dbfiddle: