有表 a b c d e f g
php codea.id = b.aid = c.aid = d.aid = e.aid = f.aid = g.aid
现在要把id为1的数据在所有表中全部删除
刚开始写的循环删除 但执行效率太慢了
有没有更好的办法使效率更高
------解决方案--------------------
delete from a where id=1;
delete from b where aid=1;
.........................
------解决方案--------------------
探讨
引用:
delete from a where id=1;
delete from b where aid=1;
.........................
我也是这么写的 循环array(a,b,c,d,e,...);然后删除的 可能由于表中数据太多(大概一百三十万条左右)
删除一条大概需要3 4秒
------解决方案--------------------
在所有表的 aid 上建索引
在循环中逐个操作
如果都是 innodb 类型表
那么在除 a 外的表的 aid 上建 a.id 的外键
只 delete from a where id=1 即可
