当前位置:网站首页>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.
边栏推荐
猜你喜欢

Linux 部署mysql 5.7全程跟踪 完整步骤 django部署

jira是什么

How to install joiplay emulator rtp

MySQL数据库(基础)

限制字符绕过
Dry goods | 4 tips for MySQL performance optimization

Optimization of aggregate mentioned at DATA AI Summit 2022
![[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]](/img/c0/1130111c90b1bc175b088894c1c18f.png)
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]

uniapp折叠框二级循环

Android security optimization - APP reinforcement
随机推荐
firewalld
WebServer流程讲解(注册模块)
Gabor滤波器学习笔记
H5跳转微信公众号解决方案
【深入浅出玩转FPGA学习14----------测试用例设计2】
image里的mode属性
Necessary artifacts - AKShare quants
joiplay模拟器如何调中文
leetcode 406. Queue Reconstruction by Height
In MySQL, the stored procedure cannot realize the problem of migrating and copying the data in the table
Android security optimization - APP reinforcement
Soft Exam Study Plan
Word文件损坏如何修复
神经网络(ANN)
Shell script if statement
Encapsulate and obtain system user information, roles and permission control
JS中? ?和??=和?.和 ||的区别
uniapp develops WeChat applet - soft exam brushing applet
uniapp开发微信小程序-软考刷题小程序
实验7(MPLS实验)