当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
K-means based user portrait clustering model
浏览器tab页之间的通信
leetcode刷题:栈与队列02(用队列实现栈)
月入1W+的自媒体达人都会用到的运营工具
中通笔试题:翻转字符串,例如abcd打印出dcba
统计字符中每个字符出现的个数
MQ学习笔记
Difference and use between require and import
Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
require与import的区别和使用
Aidl basic use
leetcode刷题:栈与队列07(滑动窗口最大值)
GCC编译
Kuberntes云原生实战一 高可用部署架构
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
都能看懂的LIS(最长上升子序列)问题[通俗易懂]
编程英语生词笔记本
微信小程序,连续播放多段视频。合成一个视频的样子,自定义视频进度条
Talking from mlperf: how to lead the next wave of AI accelerator
List announced | outstanding intellectual property service team in China in 2021









