tsql脚本将删除级联添加到现有表 [英] tsql script to add delete cascade to existing tables

查看:69
本文介绍了tsql脚本将删除级联添加到现有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在一个可用于为现有表启用级联删除的脚本。
谢谢。

is there a script that can be used to enable cascaded deletion for existing tables. Thanks.

推荐答案

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 表名

  • PARENT_TABLE_NAME 存储父母的表的名称。
    该占位符可以等于

  • FK_TABLE_NAME_PARENT_TABLE_NAME 仅仅是约束的名称 >

  • FOREIGN_KEY :子表中的字段用于与父级的连接,例如 -ParentID

  • PRIMARY_KEY :parents表中的字段,-ID

    • TABLE_NAME: name of the table where the children are stored.
    • PARENT_TABLE_NAME: name of the table where the parents are stored. This placeholders can be equal
    • FK_TABLE_NAME_PARENT_TABLE_NAME: just name for the constraint
    • FOREIGN_KEY: field in the child table for the connection with the parents, for example - ParentID
    • PRIMARY_KEY: field in the parents table, for example - ID
    • ALTER TABLE [wm].[Thumbs]  WITH NOCHECK ADD  CONSTRAINT [FK_Thumbs_Documents] FOREIGN KEY([DocID])
      REFERENCES [wm].[Documents] ([ID])
      ON DELETE CASCADE
      GO
      

      这篇关于tsql脚本将删除级联添加到现有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆