当前位置:网站首页>The difference between truncate and delete in MySQL database
The difference between truncate and delete in MySQL database
2022-07-31 00:15:00 【Miracle_ze】
The difference between Truncate and Delete
Introduction to Truncate
1. How to use
Delete table data
TRUNCATE table1;truncate is a statement of the delete function in MySQL.The function is to clear the table or truncate the table, which can only be applied to the table.The syntax of truncate is very simple, just follow the table name directly.
2. Note that permission is required for use
To execute the truncate statement, you need to have the drop permission on the table.
Logically speaking, truncate table is similar to delete statement to delete all rows or a combination of drop table and then create table statement.In order to achieve high performance, it bypasses the DML method of deleting data, therefore, it cannot be rolled back.
DML: Data Manipulation Language - the basic operation of the database, that is, adding, deleting, modifying and checking
Introduction to Delte
1. How to use
Deleting table data or views:
delete from table_name;delete from table_name where delete condition;If no WHERE clause is specified, all records in the MySQL table will be deleted.
The similarities and differences between Truncate and Delete
1. Similarities
1. Both can delete statements on the table.The delete operation is performed on the table data, but the structure is not deleted.
2. Differences
1.Truncate can only be applied to tables, Delete can be applied to tables and views, etc.
2.Truncate will reset the self-increment of the table; Delete will not.
3.Truncate will not activate delete triggers related to the table; Delete can.
4. After Truncate, the space occupied by the table and index will be restored to the original size; the delete operation will not reduce the space occupied by the table or index.
5.Delete is a DML statement, you can roll back if you don't want to commit the transaction after the operation; truncate is a DDL statement, which takes effect immediately after the operation and cannot be rolled back.
边栏推荐
猜你喜欢

firewalld

2D转换模块&&媒体查询

An easy-to-use interface testing tools - the Postman

After writing business code for many years, I found these 11 doorways, which only experts know

神经网络(ANN)

The difference between ?? and ??= and ?. and || in JS

消息队列存储消息数据的MySQL表设计

天空云变化案例

动态修改el-tab-pane 的label(整理)

transition transition && animation animation
随机推荐
一款好用的接口测试工具——Postman
Steven Giesel recently published a 5-part series documenting his first experience building an application with the Uno Platform.
How to solve types joiplay simulator does not support this game
会员生日提前了一天
Point Cloud Scene Reconstruction with Depth Estimation
joiplay模拟器rtp如何安装
借助深度估计的点云场景重建
天空云变化案例
47. 【Pointers and Arrays】
In MySQL, the stored procedure cannot realize the problem of migrating and copying the data in the table
怎么开通代付通道接口?
Necessary artifacts - AKShare quants
firewalld
A Brief Talk About MPI
Android安全性优化——APP加固
[Meng Xin problem solving] Delete the Nth node from the bottom of the linked list
web漏洞之需要准备的工作
2D转换模块&&媒体查询
(五)fastai应用
【深入浅出玩转FPGA学习13-----------测试用例设计1】