
- 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
Delete all the records from a MySQL table?
To delete all the records from a MySQL table, you can use the TRUNCATE statement.
The syntax is as follows −
TRUNCATE TABLE yourTableName;
The above syntax deletes all the records from the table. To understand the above syntax, let us create a table. The following is the query to create a table −
mysql> create table DeleteAllFromTable −> ( −> PersonId int, −> PersonName varchar(200) −> ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table with the help of insert command.
The query is as follows −
mysql> insert into DeleteAllFromTable values(100,'Johnson'); Query OK, 1 row affected (0.10 sec) mysql> insert into DeleteAllFromTable values(101,'John'); Query OK, 1 row affected (0.22 sec) mysql> insert into DeleteAllFromTable values(102,'Carol'); Query OK, 1 row affected (0.47 sec) mysql> insert into DeleteAllFromTable values(103,'Sam'); Query OK, 1 row affected (0.19 sec)
The following is the query to display all the records −
mysql> select *from DeleteAllFromTable;
The following is the output −
+----------+------------+ | PersonId | PersonName | +----------+------------+ | 100 | Johnson | | 101 | John | | 102 | Carol | | 103 | Sam | +----------+------------+ 4 rows in set (0.00 sec)
Now delete all the records from the table with the help of TRUNCATE command. The query is as follows −
mysql> TRUNCATE TABLE DeleteAllFromTable; Query OK, 0 rows affected (0.80 sec)
Since we deleted all the records above, therefore no record would be displayed when we will use the SELECT statement −
mysql> select *from DeleteAllFromTable; Empty set (0.00 sec)
Look at the above output, there are no records in the table.
- Related Articles
- Delete all records from a table in MySQL?
- How to delete all the duplicate records in a MySQL table?
- Delete records from a MySQL table by excluding non-deleted records using NOT IN
- Delete records from a MySQL table with IN() in a single query
- How to delete a single value from a MySQL table with duplicate records?
- How to delete all records from a table in Oracle using JDBC API?
- How can we delete all rows from a MySQL table?
- How can we fetch all the records from a particular MySQL table?
- A single MySQL query to insert records (not all) in the second table from the first table
- How to convert all the records in a MySQL table from uppercase to lowercase?
- Delete multiple entries from a MySQL table
- Use TRIM on all records in a MySQL table?
- How to select all the records except a row with certain id from a MySQL table?
- Take all records from one MySQL table and insert it to another?
- MySQL query to find alternative records from a table

Advertisements