The Truncate table statement is used to delete/truncate all data in the table.
Executing Code 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) What permissions does truncate need?The execution of truncate is drop first and then create, so truncate includes drop and create, which is a compound action. You don't need to grant create permission, so you only need to grant drop permission. This is the end of this article about the use of MySQL truncate table statement. For more relevant MySQL truncate table content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: Detailed explanation of eight methods to achieve CSS page bottom fixed
Table of contents 1. What is a prototype? 2. Prot...
Table of contents 1. Simple to use 2. Use DISTINC...
Table of contents 1. Background 2. What is silent...
A colleague reported that a MySQL instance could ...
I encountered a very unusual parameter garbled pro...
Table of contents 1. Mapped Types 2. Mapping Modi...
Problem Reproduction When using HTML for editing,...
1. Introduction Presto is an open source distribu...
The CSS position attribute specifies the element&...
Table of contents Immediately execute function fo...
This article shares the specific code of js canva...
Three Paradigms 1NF: Fields are inseparable; 2NF:...
<br />First think of the idea, then draw a s...
Table of contents 1. Insert statement 1.1 Insert ...
The effect to be achieved is: fixed zoom in twice...