如何计算删除中一个表中已删除的行数连接结构?
我使用以下查询从两个表中删除行
delete
itc, ic
from
incoming_tours ic
join
incoming_tours_cities itc on itc.id_parrent = ic.id
where
ic.sale = '5'
如何从 ic 表中获取受影响的行数? (mysql_affected_rows 返回总计数,我只需要一张表)。 (我在表中使用 MyISAM 引擎,这就是为什么我在这里不使用外键)
非常感谢
I use the following query, to delete the rows from two tables
delete
itc, ic
from
incoming_tours ic
join
incoming_tours_cities itc on itc.id_parrent = ic.id
where
ic.sale = '5'
How can i get the number of affected rows from ic table? (mysql_affected_rows returns the total count, i need only from one table).
(I use MyISAM engines in my tables, that is why i don't use foreign keys here)
Thanks much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
预先计算行数。
在事务中执行此操作,以确保表在 SELECT 和 DELETE 命令之间不会更改。
Count the rows beforehand.
Do it in a transaction to make sure the table does not change between the SELECT and DELETE commands.
您不能为此使用affected_rows。我认为您可以在 ic 上的删除后触发器中使用会话变量来计算已删除的行数。
You can't use affected_rows for this. I think you can use a session variable in an after delete trigger on ic to count deleted rows.