ren
ren

Reputation: 3993

SQL server: what does this sql statement mean

I've been comparing databases using vs 2010 scheme comparing tool and it generated some stuff which is not clear. For example at the end of the script it has this statement:

ALTER TABLE [dbo].[My_table] WITH CHECK CHECK CONSTRAINT [FK_FOREIGN_ID];

Can anyone explain what this means?

Upvotes: 2

Views: 403

Answers (2)

Thomas
Thomas

Reputation: 64635

That tells SQL Server to validate the constraint against new rows. The counter example would be to use WITH NOCHECK to temporarily disable validation checks for new rows.

ALTER TABLE (Transact-SQL) (WITH CHECK | WITH NOCHECK )

Upvotes: 1

Martin Smith
Martin Smith

Reputation: 453037

It means that existing data should be checked against the constraint when it is added.

Failure to have the CHECK CHECK leaves your constraints untrusted and they cannot be used by the query optimiser.

Upvotes: 3

Related Questions