MySQL truncate table語句的使用
Truncate table語句用來刪除/截?cái)啾砝锏乃袛?shù)據(jù)
- 和delete刪除所有表數(shù)據(jù)在邏輯上含義相同,但性能更快
- 類似執(zhí)行了drop table和create table兩個(gè)語句
執(zhí)行代碼
mysql> select * from students_bak; +-----+----------+--------+---------+ | sid | sname | gender | dept_id | +-----+----------+--------+---------+ | 101 | zhangsan | male | 10 | | 1 | aa | 1 | 1 | +-----+----------+--------+---------+ 2 rows in set (0.00 sec) mysql> truncate table students_bak; Query OK, 0 rows affected (0.16 sec) mysql> select * from students_bak; Empty set (0.00 sec) mysql> set autocommit=off; Query OK, 0 rows affected (0.01 sec) mysql> select * from students3; +-----+-------+--------+---------+--------+ | sid | sname | gender | dept_id | sname2 | +-----+-------+--------+---------+--------+ | 100 | NULL | 1 | 1 | NULL | +-----+-------+--------+---------+--------+ 1 row in set (0.01 sec) mysql> truncate table students3; Query OK, 0 rows affected (0.06 sec) mysql> rollback; Query OK, 0 rows affected (0.00 sec) mysql> select * from students3; Empty set (0.00 sec) mysql> delete from students; Query OK, 5 rows affected (0.00 sec) mysql> select * from students; Empty set (0.00 sec) mysql> rollback; Query OK, 0 rows affected (0.07 sec) mysql> select * from students; +-----+-------+--------+---------+ | sid | sname | gender | dept_id | +-----+-------+--------+---------+ | 1 | aa | 3 | 1 | | 4 | cc | 3 | 1 | | 5 | dd | 1 | 2 | | 6 | aac | 1 | 1 | | 10 | a | 1 | 1 | +-----+-------+--------+---------+ 5 rows in set (0.00 sec)
truncate需要什么權(quán)限
truncate的執(zhí)行是先drop后create的, 所以truncate包含drop和create,是一個(gè)復(fù)合的動(dòng)作, 對(duì)于create不用賦予, 所以只需要賦予drop權(quán)限就可以了
到此這篇關(guān)于MySQL truncate table語句的使用的文章就介紹到這了,更多相關(guān)MySQL truncate table內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Navicat連接遠(yuǎn)程服務(wù)器里docker中mysql的方法(已解決)
相信大家都有在遠(yuǎn)程服務(wù)器上進(jìn)行開發(fā)吧,其中MySQL的使用率應(yīng)該也會(huì)挺高,這篇文章主要給大家介紹了關(guān)于Navicat連接遠(yuǎn)程服務(wù)器里docker中mysql的相關(guān)資料,需要的朋友可以參考下2024-04-04
dbeaver如何導(dǎo)出mysql數(shù)據(jù)庫
DBeaver導(dǎo)出MySQL數(shù)據(jù)庫的簡(jiǎn)便方法:右鍵點(diǎn)擊表選擇“Tools”->“Dump database”,設(shè)定輸出文件夾(例如桌面),點(diǎn)擊開始即可導(dǎo)出SQL文件,此方法基于個(gè)人經(jīng)驗(yàn),供參考2024-10-10
MySQL中存儲(chǔ)時(shí)間的最佳實(shí)踐指南
這篇文章主要給大家介紹了關(guān)于MySQL中存儲(chǔ)時(shí)間的最佳實(shí)踐,文中詳細(xì)介紹了哪種存儲(chǔ)時(shí)間的方式更好,對(duì)大家學(xué)習(xí)或者使用mysql具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2021-07-07

