MySQL:截断表与从表中删除

编程入门 行业动态 更新时间:2024-10-21 10:34:01
本文介绍了MySQL:截断表与从表中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

什么时候使用DELETE命令而不是TRUNCATE命令?我试图在Internet上找到,但是两个命令都删除了数据;我无法分辨出差异.

When do we use the DELETE command versus the TRUNCATE command? I am trying to find on the Internet but both commands delete the data; I can't tell the difference.

推荐答案

从表中删除

1. DELETE is a DML Command. 2. DELETE statement is executed using a row lock, each row in the table is locked for deletion. 3. We can specify filters in where clause 4. It deletes specified data if where condition exists. 5. Delete activates a trigger because the operation are logged individually. 6. Slower than truncate because, it keeps logs. 7. Rollback is possible. 8. LIMIT clause can also be used to set a limit on the number of rows to be deleted. 9. ORDER BY clause can be used in DELETE statement. In this case, the rows are deleted in the specified order.

截断表

1. TRUNCATE is a DDL command. 2. TRUNCATE TABLE always locks the table and page but not each row. 3. Cannot use Where Condition. 4. It Removes all the data reset the auto increment number. 5. TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. 6. Faster in performance wise, because it doesn't keep any logs. 7. Rollback is possible. 8. Cannot use LIMIT and ORDER BY.

与TRANSACTION一起使用时,可以回滚

Delete 和 TRUNCATE . 如果有一个具有自动递增功能的主键,则truncate将重置计数器.

DELETE and TRUNCATE both can be rolled back when used with TRANSACTION. If there is a primary key with auto increment, truncate will reset the counter.

更多推荐

MySQL:截断表与从表中删除

本文发布于:2023-10-27 23:17:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534824.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!