如何重构这个多表删除语句
任何人都可以建议一种更干净的方法来删除一个查询中具有一对多关系的行吗?
这是可行的,但我对 using
子句或 delete
不太熟悉,所以我不完全理解它是如何工作的。
DELETE FROM ip_record,
entry using ip_record
inner join entry
where ip_record.site_id = ?
and ip_record.ip = ?
and ip_record.id = entry.ip_id
我有一个想法,这可以通过级联更干净地完成,但我对约束有一种非理性的恐惧。数据库是MySQL。
Can anyone suggest a cleaner method to delete rows with a one-to-many relationship in one query?
This works, but I'm not very familiar with the using
clause or delete
, so I don't fully understand how it works.
DELETE FROM ip_record,
entry using ip_record
inner join entry
where ip_record.site_id = ?
and ip_record.ip = ?
and ip_record.id = entry.ip_id
I have a notion that this could be done more cleanly with a cascade, but I have an irrational fear of constraints. The DB is MySQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,按如下方式添加约束
,然后您就可以用来
执行之前需要连接的操作。
Yes, add the constraint as follows
and then you can just use
to do what previously required a join.