MySQL:如何查找特定主键在其他表中用作外键的位置?
我正在努力实现一个功能,以防止删除数据库中的某些元素(通过前端),如果它们在其他表中具有与它们关联的其他项目。否则,其他表正在寻找不存在的键。
如果你明白我的帽子就送给你了。
我有许多组表需要查看,需要一个 SQL 查询或一个 MySQL Workbench 功能来告诉我,在输入主键(列名,而不是实际值)时,该键是否在其他地方用作外键。
否则,如果有人知道一个临时解决方法,那就太好了!
I'm working on implementing a function to prevent removal of certain elements in a database (through the front end) if they have other items associated with them in other tables. Otherwise those other tables are looking for keys that aren't there.
If you understood that my hat is off to you.
I have many sets of tables to look through and need either a SQL query or a MySQL Workbench feature that can tell me, on entry of the primary key (column name, not actual value), if that key is used as a foreign key somewhere else.
Otherwise if anyone knows an offhand workaround, that would be great too!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这篇文章从 information_Schema 表中检索此信息。
1)如果您想从代码中处理这些表,请将它们作为容器(例如代码中的 ArrayList)获取并执行您的逻辑。
2) 如果您想从存储过程中处理这些表,请使用临时表来完成与通过容器在 Java 代码中执行的相同工作。
A solution is described in this post to retrieve this information from information_Schema table.
1) If you want to work on these tables from your code, then fetch them as a container, for example ArrayList in your code and perform your logic.
2) If you want to work on these tables from your Stored Procedure, then use temporary tables to achive the same work you'd do in your java code through containers.