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 table named users use following command. You must select database first before running below command.
1 | mysql> TRUNCATE TABLE users; |
Example – MySQL Truncate Table For example, I have a table named users with following records in a database. First, check the available data in the table. After that truncate table and again check.
1 2 3 4 5 6 7 8 9 | 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) |
…
Read More