我在 SQL Server 2005 中有一个带有外键的表,它被禁用以加载大量数据,然后重新启用:
例子:
alter table table1 nocheck constraint fk_1
go
lots of inserts...
go
alter table table1 check constraint fk_1
go
现在,问题是:有没有办法重新检查刚刚插入的数据?
我在 SQL Server 2005 中有一个带有外键的表,它被禁用以加载大量数据,然后重新启用:
例子:
alter table table1 nocheck constraint fk_1
go
lots of inserts...
go
alter table table1 check constraint fk_1
go
现在,问题是:有没有办法重新检查刚刚插入的数据?
重复“检查”这个词的语法看起来有点傻,但你想要的是:
alter table table1 with check check constraint fk_1
go
添加“with check”选项将根据约束验证现有数据。这样做还可以防止约束变得不受信任。
如果任何现有数据违反约束,您将收到如下所示的错误:
The ALTER TABLE statement conflicted with the CHECK constraint "fk_1".