SQL TRUNCATE TABLE
Use MySQL TRUNCATE TABLE statement to delete all table content. This doesn’t remote table structure. The truncate table also reset the auto-increment values.
Syntax:
TRUNCATE TABLE table_name
MySQL Truncate Table Statement
For example, to remove all data from a table named users use the following command. You must select the database first before running the below command.
| mysql> TRUNCATE TABLE users; |
Example – MySQL Truncate Table
For example, I have a table named users with the following records in a database. First, check the available data in the table. After that truncate table and again check.
mysql> SELECT * FROM users; +----+-----------+-----------------+--------------------+---------------------+--------+ | ID | username | password | email | signup_date | status | +----+-----------+-----------------+--------------------+---------------------+--------+ | 1 | admin | $P$BXq.6qP/fAtg | rahul@example.com | 2017-11-04 19:11:53 | 1 | +----+-----------+-----------------+--------------------+---------------------+--------+ | 2 | tecadmin | $P$Kxn3.s8KD/39 | hello@example.com | 2017-11-03 07:37:07 | 0 | +----+-----------+-----------------+--------------------+---------------------+--------+ 2 row in set (0.01 sec) |
Now execute the truncate table statement on the user's table.
mysql> TRUNCATE TABLE users;
After running the truncate table statement, again check the table values.
mysql> SELECT * FROM users;
Empty set (0.00 sec)
0 Comments
CAN FEEDBACK
Emoji