当前位置:网站首页>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 .
边栏推荐
- Basic operations of databases and tables ----- classification of data
- 共用体(union)详解【C语言】
- GCC compilation options
- [golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
- Classification, understanding and application of common methods of JS array
- Navigator object (determine browser type)
- ES6 grammar summary -- Part 2 (advanced part es6~es11)
- Redis cache update strategy, cache penetration, avalanche, breakdown problems
- Selective sorting and bubble sorting [C language]
- Arduino uno R3 register writing method (1) -- pin level state change
猜你喜欢

基于Redis的分布式ID生成器

Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】

open-mmlab labelImg mmdetection

JS variable types and common type conversions

程序员老鸟都会搞错的问题 C语言基础 指针和数组

高通&MTK&麒麟 手机平台USB3.0方案对比

RT thread API reference manual

Oppo vooc fast charging circuit and protocol

Arduino uno R3 register writing method (1) -- pin level state change

MP3mini播放模块arduino<DFRobotDFPlayerMini.h>函数详解
随机推荐
JS變量類型以及常用類型轉換
RuntimeError: cuDNN error: CUDNN_ STATUS_ NOT_ INITIALIZED
Comparison of solutions of Qualcomm & MTK & Kirin mobile platform USB3.0
关于Gateway中使用@Controller的问题
【ESP32学习-1】Arduino ESP32开发环境搭建
Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
Arduino JSON data information parsing
RT thread API reference manual
Pytorch four commonly used optimizer tests
Kaggle competition two Sigma connect: rental listing inquiries
. elf . map . list . Hex file
MySQL占用内存过大解决方案
共用体(union)详解【C语言】
Knowledge summary of request
高通&MTK&麒麟 手机平台USB3.0方案对比
Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
Common properties of location
Who says that PT online schema change does not lock the table, or deadlock
MySQL takes up too much memory solution
JS regular expression basic knowledge learning