Home >Backend Development >PHP Tutorial >mysql多表删除 快点 再快点.该怎么处理

mysql多表删除 快点 再快点.该怎么处理

WBOY
WBOYOriginal
2016-06-13 10:52:521115browse

mysql多表删除 快点 再快点....
有表 A B C D E F G

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->A.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 即可
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn