gpt4 book ai didi

tsql - 更改表 [dbo].[MyTable] 检查约束 [FK_MyTable_SomeCol]

转载 作者:行者123 更新时间:2023-12-03 12:16:00 25 4
gpt4 key购买 nike

如果我用外键编写一个表,它看起来像这样:

GO
ALTER TABLE [dbo].[MyTable] WITH CHECK ADD CONSTRAINT [FK_MyTable_SomeCol] FOREIGN KEY([SomeCol])
REFERENCES [dbo].[MyOtherTable] ([SomeCol])
GO
ALTER TABLE [dbo].[MyTable] CHECK CONSTRAINT [FK_MyTable_SomeCol]
GO

( ALTER TABLE [dbo].[MyTable] CHECK CONSTRAINT [FK_MyTable_SomeCol] ) 的第二部分是什么?

最佳答案

这是约束脚本方式的产物——尽管没有必要指定这些选项(因为它们是新约束的默认值),但同一个生成器也可以生成 NOCHECK选项完全相同。
DocumentationALTER TABLE表示 CHECK 的两种不同用途/NOCHECK :

WITH CHECK | WITH NOCHECK

Specifies whether the data in the table is or is not validated against a newly added or re-enabled FOREIGN KEY or CHECK constraint. If not specified, WITH CHECK is assumed for new constraints, and WITH NOCHECK is assumed for re-enabled constraints.


和:

{ CHECK | NOCHECK } CONSTRAINT

Specifies that constraint_name is enabled or disabled.


所以一个选项是说“检查表的当前内容”,另一种是说“在添加新数据时验证它”。

关于tsql - 更改表 [dbo].[MyTable] 检查约束 [FK_MyTable_SomeCol],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9974506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com