
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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.
- Related Articles
- How do I select four random tables from a MySQL database having thousands of tables?
- How can I merge two MySQL tables?
- How do you properly ignore Exceptions in Python?
- How can I sum columns across multiple tables in MySQL?
- Truncate with condition in MySQL?
- How do I lag columns in MySQL?
- How can I change the default sort order of MySQL tables?
- How can I see the description of a MySQL Temporary Tables?
- How can I the date of creation and updation of tables in MySQL?
- MySQL truncate text with ellipsis?
- How do I create a view in MySQL?
- How do I delete blank rows in MySQL?
- How do I use the @ sign in MySQL?
- How do I re-format datetime in MySQL?
- How do I disable Strict Mode in MySQL?

Advertisements