具有FK约束的MySQL/InnoDB:查找受级联删除影响的表/行

时间:2022-05-21 22:56:43

I have a MySQL/InnoDB database set up with FK constraints. If I delete a row in a 'root' table, the dependent tables will have corresponding rows deleted.

我有一个使用FK约束的MySQL/InnoDB数据库。如果我删除“根”表中的一行,则相关表将删除相应的行。

How can I show what has been deleted, or at least which tables have been affected?

如何显示已删除的内容,或至少显示已影响哪些表?

Is there any simple way or will I need to write a tool to compare before and after?

有没有什么简单的方法,或者我需要写一个工具来比较前后对比?

Would a replication log show what's going on?

复制日志会显示发生了什么吗?

1 个解决方案

#1


4  

No, there is no way to show what was deleted No, it will not show up in replication log

不,没有办法显示被删除的内容不,它不会显示在复制日志中

Only thing I can think of, is to query information_schema views to see what tables have FK constraints depending on 'root' table.

我能想到的唯一一件事,就是查询information_schema视图,看看根据“root”表有哪些表具有FK约束。

SELECT DISTINCT
  TABLE_NAME FROM REFERENTIAL_CONSTRAINTS 
WHERE 
  CONSTRAINT_SCHEMA = 'yourDatabase'
  AND REFERENCED_TABLE_NAME = 'rootTable'
  AND DELETE_RULE = 'CASCADE'

#1


4  

No, there is no way to show what was deleted No, it will not show up in replication log

不,没有办法显示被删除的内容不,它不会显示在复制日志中

Only thing I can think of, is to query information_schema views to see what tables have FK constraints depending on 'root' table.

我能想到的唯一一件事,就是查询information_schema视图,看看根据“root”表有哪些表具有FK约束。

SELECT DISTINCT
  TABLE_NAME FROM REFERENTIAL_CONSTRAINTS 
WHERE 
  CONSTRAINT_SCHEMA = 'yourDatabase'
  AND REFERENCED_TABLE_NAME = 'rootTable'
  AND DELETE_RULE = 'CASCADE'