TSQL:获取受级联删除影响的所有表
我正在寻找一个 SQL 脚本,该脚本将列出从表 X 中删除记录时将受到影响的所有表。 它还应该列出“树”下受影响的依赖表,因为受影响的表将对其他表进行级联删除,这反过来又会影响其他表等。
I'm looking for a SQL script that will list all tables that will be affected when deleting a record from table X.
It should also list the dependent tables affected down the "tree" as the affected tables will have cascade deletes to other, which in turn will affect others etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用递归 CTE 生成受影响表的完整层次结构,例如,
这将输出类似以下内容的内容:
db<>fiddle 示例
You can use a recursive CTE to generate a full hierarchy of tables affected, e.g.
This will output something like:
Example on db<>fiddle