首页 > 代码库 > Mysql delete操作
Mysql delete操作
以下摘自官方文档:
语法:
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROMtbl_name
[PARTITION (partition_name
,...)] [WHEREwhere_condition
] [ORDER BY ...] [LIMITrow_count
]
性能:
When you do not need to know the number of deleted rows, theTRUNCATE TABLE
statement is a faster way to empty a table than aDELETE
statement with noWHERE
clause. UnlikeDELETE
,TRUNCATE TABLE
cannot be used within a transaction or if you have a lock on the table. SeeSection 14.1.34, “TRUNCATE TABLE Syntax” and Section 14.3.5, “LOCK TABLES and UNLOCK TABLES Syntax”.
简单理解是:truncate 在不锁表的情况下,很快:
如果想用delete删除快点:
The time required to delete individual rows in aMyISAM
table is exactly proportional to the number of indexes. To delete rows more quickly, you can increase the size of the key cache by increasing thekey_buffer_size
system variable
可以配置的key_buffer_size大小
多表删除:
(1)不带别名
DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;
Or:
DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;
(2)带别名:必须写别名:
If you declare an alias for a table, you must use the alias when referring to the table:
DELETE t1 FROM test AS t1, test2 WHERE ...
Correct:
DELETE a1, a2 FROM t1 AS a1 INNER JOIN t2 AS a2 WHERE a1.id=a2.id; DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a1.id=a2.id;
Mysql delete操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。