- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I truncate tables properly in MySQL?
This means that you need to first set foreign_key_check to disable and after that you need to truncate tables. The syntax is as follows −
set FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE yourTableName1; TRUNCATE TABLE yourTableName2; TRUNCATE TABLE yourTableName3; . . . . TRUNCATE TABLE yourTableNameN; set FOREIGN_KEY_CHECKS = 1;
Now, truncate some tables from our database test. The query is as follows −
mysql> set FOREIGN_KEY_CHECKS = 0; Query OK, 0 rows affected (0.00 sec) mysql> truncate table skiplasttenrecords; Query OK, 0 rows affected (0.97 sec) mysql> truncate table searchtextdemo; Query OK, 0 rows affected (0.89 sec) mysql> set FOREIGN_KEY_CHECKS = 1; Query OK, 0 rows affected (0.00 sec)
To cross check whether the data is present in the table or not −
mysql> select *from searchtextdemo; Empty set (0.00 sec) mysql> select *from skiplasttenrecords; Empty set (0.00 sec)
Empty set tells that there are no record in the table.
- How do I select four random tables from a MySQL database having thousands of tables?
- How do you properly ignore Exceptions in Python?
- How can I merge two MySQL tables?
- How can I sum columns across multiple tables in MySQL?
- How do I lag columns in MySQL?
- Truncate with condition in MySQL?
- How do I remove a MySQL database?
- How do I create a view in MySQL?
- How do I delete blank rows in MySQL?
- How do I re-format datetime in MySQL?
- How do I use the @ sign in MySQL?
- MySQL truncate text with ellipsis?
- If I truncate a table, should I also add indexes?
- How can I change the default sort order of MySQL tables?
- How can I see the description of a MySQL Temporary Tables?