当前位置:网站首页>Detailed explanation of truncate usage
Detailed explanation of truncate usage
2022-07-06 12:18:00 【wx5caecf2ed0645】
Preface :
When we want to empty a table , Often use truncate sentence . Most of the time we just care about meeting the needs , Instead of thinking about the use of such statements and considerations . This article mainly introduces truncate How to use sentences and what to pay attention to .
1.truncate Use the syntax
truncate It is used to empty or truncate a table , It only works on the table .truncate The grammar of is very simple , Follow the table name directly , for example :truncate table tbl_name
perhaps truncate tbl_name
.
perform truncate Statement needs to have a table of drop jurisdiction , Logically speaking ,truncate table Be similar to delete Delete all line statements or drop table And then again create table The combination of sentences . For high performance , It bypasses the deletion of data DML Method , therefore , It cannot be rolled back . Even though truncate table And delete be similar , But it's classified as DDL Statement instead of DML sentence .
2.truncate And drop,delete Comparison of
It said truncate And delete,drop Very similar , In fact, these three are quite different from each other , The following is a simple comparison of the similarities and differences of the three .
- truncate And drop yes DDL sentence , Cannot roll back after execution ;delete yes DML sentence , Roll back .
- truncate It only works on the table ;delete,drop It can act on the table 、 View etc. .
- truncate All rows in the table will be cleared , But table structure and its constraints 、 Index and so on remain unchanged ;drop It will delete the structure of the table and the constraints it depends on 、 Index, etc. .
- truncate Will reset the table's self increment ;delete Can't .
- truncate Table related drop triggers are not activated ;delete Sure .
- truncate After that, the space occupied by the table and index will be restored to the original size ;delete The operation does not reduce the space occupied by the table or index ,drop Statement to free up all the space occupied by the table .
3.truncate Usage scenarios and precautions
Through the introduction above , It's easy for us to come to the conclusion that truncate Usage scenarios of statements , That is, when the data in the table is not needed at all truncate. If you want to delete some data, use delete, Pay attention to take where Clause ; If you want to delete a table , Of course with drop; If you want to keep the table and delete all data regardless of the transaction , use truncate that will do ; If it's about business , Or want to trigger trigger, Or use it delete; If it's defragmenting the table , It can be used truncate And then re insert the data .
No matter what ,truncate Watch is a high-risk operation , Especially in the production environment, be more careful , Here are a few notes , I hope you can use it for reference .
- truncate Unable to get binlog Roll back .
- truncate All data will be cleared and the execution speed will be very fast .
- truncate Cannot use... On a table that has a foreign key constraint reference .
- perform truncate need drop jurisdiction , It is not recommended to give an account number drop jurisdiction .
- perform truncate Be sure to check again and again before , It's better to back up the data in the following table in advance .
边栏推荐
- Common properties of location
- Kaggle competition two Sigma connect: rental listing inquiries
- Walk into WPF's drawing Bing Dwen Dwen
- [Red Treasure Book Notes simplified version] Chapter 12 BOM
- Redis based distributed locks and ultra detailed improvement ideas
- 基於Redis的分布式ID生成器
- (一)R语言入门指南——数据分析的第一步
- Detailed explanation of Union [C language]
- 共用体(union)详解【C语言】
- ESP learning problem record
猜你喜欢
arduino JSON数据信息解析
共用体(union)详解【C语言】
[esp32 learning-1] construction of Arduino esp32 development environment
Time slice polling scheduling of RT thread threads
JS数组常用方法的分类、理解和运用
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
JS variable types and common type conversions
JS function promotion and declaration promotion of VaR variable
Whistle+switchyomega configure web proxy
随机推荐
.elf .map .list .hex文件
[esp32 learning-2] esp32 address mapping
JS正则表达式基础知识学习
Gateway fails to route according to the service name, and reports an error service unavailable, status=503
Pat 1097 duplication on a linked list (25 points)
JS 函数提升和var变量的声明提升
Basic operations of databases and tables ----- modifying data tables
C语言函数之可变参数原理:va_start、va_arg及va_end
Keyword inline (inline function) usage analysis [C language]
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
Reno7 60W super flash charging architecture
嵌入式启动流程
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
Symbolic representation of functions in deep learning papers
Générateur d'identification distribué basé sur redis
arduino JSON数据信息解析
Mysqldump error1066 error solution
RuntimeError: cuDNN error: CUDNN_ STATUS_ NOT_ INITIALIZED
Arduino gets the length of the array
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect