mysql截断表_MySQL:截断表与从表中删除

bd96500e110b49cbb3cd949968f18be7.png

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.

解决方案

DELETE FROM TABLE

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.

TRUNCATE TABLE

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.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值