有没有办法生成级联删除语句?
假设我希望删除表 AI 中的一行,但其他表中有多个外键约束。有没有办法自动生成删除命令? 我认为应该存在一种工具,可以递归地查看外键,然后生成删除语句来处理所有外键,但我找不到。
我在 MSSql server2008 上
Let's say I have a row in Table A I wish to delete but there a multiple foreign key constraints in other tables. Is there a way to automatically generate the delete command?
I think a tool that would recursively look at the foreign keys and in turn generate a delete statement to take care of all foreign keys should exist, but I can't find one.
I'm on MSSql server2008
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置外键关系时,您可以添加一个
ON DELETE CASCADE
。MSDN 级联引用完整性约束
SO甚至有一个解决方案,您不将其添加到表中:
在 SQL 中Server 2005,我可以在不设置表属性的情况下进行级联删除吗?
When setting up your Foreign Key relationships there is an
ON DELETE CASCADE
you can add.MSDN Cascading Referential Integrity Constraints
SO even has a solution where you are not adding it to the table:
In SQL Server 2005, can I do a cascade delete without setting the property on my tables?