DBHow to use TRUNCATE for MYSQL

How to use TRUNCATE for MYSQL

This article discusses how to delete all the rows of a table using the TRUNCATE clause.

In the previous article, we learned how to delete data using the DELETE statement. However, if we intend to delete all the rows from a table then a faster route is to use the TRUNCATE statement. Generally, we don’t want to delete all the table rows except in the case of temporary tables. The TRUNCATE statement drops a table and recreates it for faster processing. MySQL doesn’t count the number of rows affected and may show the count to be zero or non-zero, but the number doesn’t reflect the actual number of rows affected.

Example Syntax :
TRUNCATE table;

Execute the following query to remove all the rows from the table:

TRUNCATE Actors;

Note that TRUNCATE doesn’t work with locking or transactions and is the equivalent of DELETE when used with InnoDB tables. InnoDB refers to a particular type of database engine and is covered in the lessons ahead.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe Today

GET EXCLUSIVE FULL ACCESS TO PREMIUM CONTENT

Get unlimited access to our EXCLUSIVE Content and our archive of subscriber stories.

Exclusive content

Latest article

More article