is there a script that can be used to enable cascaded deletion for existing tables. Thanks.
是否有一个脚本可以用于对现有表执行级联删除。谢谢。
1 个解决方案
#1
15
ALTER TABLE [wm].[TABLE_NAME] WITH NOCHECK ADD CONSTRAINT [FK_TABLE_NAME_PARENT_TABLE_NAME] FOREIGN KEY([FOREIGN_KEY])
REFERENCES [wm].[PARENT_TABLE_NAME] ([PRIVATE_KEY])
ON DELETE CASCADE
GO
-
TABLE_NAME
: name of the table where the children are stored. - 表_name:存储子元素的表的名称。
-
PARENT_TABLE_NAME
: name of the table where the parents are stored. This placeholders can be equal - PARENT_TABLE_NAME:存储父类的表的名称。这个占位符可以是相等的
-
FK_TABLE_NAME_PARENT_TABLE_NAME
: just name for the constraint - FK_TABLE_NAME_PARENT_TABLE_NAME:只是约束的名称
-
FOREIGN_KEY
: field in the child table for the connection with the parents,for example - ParentID
- FOREIGN_KEY:子表中用于与父类连接的字段,例如ParentID
-
PRIMARY_KEY
: field in the parents table,for example - ID
- PRIMARY_KEY:父表中的字段,例如- ID
ALTER TABLE [wm].[Thumbs] WITH NOCHECK ADD CONSTRAINT [FK_Thumbs_Documents] FOREIGN KEY([DocID])
REFERENCES [wm].[Documents] ([ID])
ON DELETE CASCADE
GO
#1
15
ALTER TABLE [wm].[TABLE_NAME] WITH NOCHECK ADD CONSTRAINT [FK_TABLE_NAME_PARENT_TABLE_NAME] FOREIGN KEY([FOREIGN_KEY])
REFERENCES [wm].[PARENT_TABLE_NAME] ([PRIVATE_KEY])
ON DELETE CASCADE
GO
-
TABLE_NAME
: name of the table where the children are stored. - 表_name:存储子元素的表的名称。
-
PARENT_TABLE_NAME
: name of the table where the parents are stored. This placeholders can be equal - PARENT_TABLE_NAME:存储父类的表的名称。这个占位符可以是相等的
-
FK_TABLE_NAME_PARENT_TABLE_NAME
: just name for the constraint - FK_TABLE_NAME_PARENT_TABLE_NAME:只是约束的名称
-
FOREIGN_KEY
: field in the child table for the connection with the parents,for example - ParentID
- FOREIGN_KEY:子表中用于与父类连接的字段,例如ParentID
-
PRIMARY_KEY
: field in the parents table,for example - ID
- PRIMARY_KEY:父表中的字段,例如- ID
ALTER TABLE [wm].[Thumbs] WITH NOCHECK ADD CONSTRAINT [FK_Thumbs_Documents] FOREIGN KEY([DocID])
REFERENCES [wm].[Documents] ([ID])
ON DELETE CASCADE
GO