当前位置:网站首页>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.
边栏推荐
猜你喜欢
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
Homework: iptables prevent nmap scan and binlog
An easy-to-use interface testing tools - the Postman
Steven Giesel recently published a 5-part series documenting his first experience building an application with the Uno Platform.
46.<list链表的举列>
joiplay模拟器报错如何解决
After writing business code for many years, I found these 11 doorways, which only experts know
How to solve types joiplay simulator does not support this game
寄存器(汇编语言)
C# VSCode & Rider引用命名空间快捷键
随机推荐
天空云变化案例
leetcode:127. 单词接龙
xss的绕过
作业:iptables防止nmap扫描以及binlog
数据清洗-使用es的ingest
XSS相关知识
Android安全性优化——APP加固
uniapp folding box secondary loop
flex-direction容器属性
uniapp开发微信小程序-软考刷题小程序
一款好用的接口测试工具——Postman
47. 【Pointers and Arrays】
软件开发设计流程
借助深度估计的点云场景重建
游戏商城表建立
Machine Learning 1-Regression Model (2)
joiplay模拟器不支持此游戏类型怎么解决
Soft Exam Study Plan
HCIP Day 15 Notes
MPI简谈