使用圆形外键从两个表中删除 [英] Delete from two tables with circular foreign keys
本文介绍了使用圆形外键从两个表中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个桌子
TableOne (TABLE_ONE_ID (pk), TABLE_TWO_ID (fk), ...(something else) )
TableTwo (TABLE_TWO_ID (pk), TABLE_ONE_ID (fk), ...(something else) )
如何从这些表中删除记录?
How can I delete records from these tables?
P.S.我认为这是错误的设计,但这不是我的错,并且我没有更改数据库结构的权限.我只需要知道如何从这些表中删除记录即可.
P.S. I think that it is bad design, but this is not my fault and I don't have permission to change the database structure. I just need to know how to delete records from these tables.
推荐答案
我不确定实现此目的的最佳方法,但我可能会做类似的事情:
I'm not sure of the best way to go about this but I would probably do something like:
UPDATE TableOne SET TABLE_TWO_ID = null;
DELETE FROM TableTwo;
DELETE FROM TableOne;
这篇关于使用圆形外键从两个表中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文