如何重新检查sql server表中已有数据的主/外键约束?
我在 SQL Server 2005 中有一个带有外键的表,它被禁用以加载大量数据,然后重新启用:
示例:
alter table table1 nocheck constraint fk_1
go
lots of inserts...
go
alter table table1 check constraint fk_1
go
现在,问题:有没有办法重新检查刚刚插入的数据?
I have a table in SQL Server 2005 with a foreign key and it was disable for huge data loading, and then re-enabled:
Example:
alter table table1 nocheck constraint fk_1
go
lots of inserts...
go
alter table table1 check constraint fk_1
go
Now, the question: is there a way to re-check this just inserted data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重复使用“check”一词的语法看起来有点傻,但您想要的是:
添加“with check”选项将根据约束验证现有数据。这样做还可以防止约束变得不受信任< /a>.
如果任何现有数据违反约束,您将收到如下错误:
The syntax looks a little silly with the word "check" repeated, but what you want is:
Adding the "with check" option will validate existing data against the constraint. Doing this will also prevent the constraint from becoming untrusted.
If any existing data violates the constraint, you'll get an error that will look like this: