Faster Alternative to MySQL Delete Table Contents / Truncate


From time to time you might have some rather big tables that you want to delete all the data quickly and start afresh.

You have a few options at this point. The first you?ll probably look at is:

DELETE FROM `table_name`

The benefit of doing this is DELETE provides the ability to Rollback if all hell breaks loose, but it also means that it will take longer because it requires more memory to store all this additional data

Options 2 is to just truncate the table:

TRUNCATE `table_name`

This is the quicker of the 2 options so far and will merely delete all rows as is

Option 3 is to clone the table structure and then rename tables:

CREATE TABLE table_name2 LIKE table_name;<br> RENAME TABLE table_name TO table_name3;<br> RENAME TABLE table_name2 TO table_name;

This last option is the quickest and can be performed on very large tables with lightning speed results