当前位置:网站首页>MySQL empties table data
MySQL empties table data
2022-07-01 21:55:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Clear the table data There are three ways
1 、truncate ( fast ) The auto increment field is cleared from 1 Start Empty the whole table first
2、drop Delete table directly … Nothing, nothing … … … …
3、delete Slow batch The auto increment field is not empty
MySQL Clear table data command :truncate
explain : Delete content 、 Free space without deleting definition , That is, the structure of the data table is still . And drop The difference is , It just empties the table data , It's gentle .
truncate table Table name
Be careful :
Cannot be associated with where Use it together . truncate Deleting data is not allowed rollback Of . truncate After deleting the data, it will reset Identity( Identity column 、 Self increasing field ), It is equivalent to that the auto increment column will be set to the initial value , Again from 1 Start recording , Instead of following the original ID Count . truncate Do not write to the server after deleting data log, The overall deletion speed is fast . truncate Do not activate after deleting data trigger( trigger ).
MySQL Delete table command :drop
explain : Delete content and definition , Release space . To put it simply, take out the whole table . It is impossible to add new data in the future , Unless a new table is added .
drop table Table name ;
Or is it Add conditions
drop table if exists Table name
Be careful :
drop Not only clear the table data, but also delete the table structure .
MySQL Syntax for clearing the contents of the data table :delete
explain : Deleting content does not delete definition , Don't free up space . among ,delete table tb Although it is also to delete the data of the whole table , But the process is painful ( The system deletes... Line by line , More efficient truncate low ).
delete from Table name where id='1';
Or is it Without conditions
delete from Table name ;
Be careful :
delete meaning : Which table data do you want to delete ? Which lines do you want to delete ? delete You can delete a line , You can also delete multiple lines ; If not where Conditions , Delete all data in the table , It's very dangerous ! This is not recommended !
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/130488.html Link to the original text :https://javaforall.cn
边栏推荐
猜你喜欢
随机推荐
js如何获取集合对象中某元素列表
【级联分类器训练参数】Training Haar Cascades
pytest合集(2)— pytest运行方式
股票手机开户哪个app好,安全性较高的
matlab遍历图像、字符串数组等基本操作
AIDL基本使用
分离字符串中的字母和数字并使得字母在前数组在后
个人炒股怎样开户?安全吗。
leetcode刷题:栈与队列02(用队列实现栈)
Pytest Collection (2) - mode de fonctionnement pytest
开环和闭环是什么意思?
K-means based user portrait clustering model
PMP与NPDP之间的区别是什么?
Electron学习(三)之简单交互操作
上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
最近公共祖先离线做法(tarjan)
CNN卷积神经网络原理讲解+图片识别应用(附源码)[通俗易懂]
C中main函数的几种写法
旁路由设置的正确方式
BC35&BC95 ONENET MQTT(旧)