MySQL emptying a table

Just a quick MySQL optimization note. Many times we're required to clear a database table and reset the auto increment counter. This is common with import scripts (importing data from Excel, etc).

The uncool way to do it:

DELETE FROM myTable
ALTER TABLE myTable AUTO_INCREMENT = 1

The cool (and more efficient) way to do it:

TRUNCATE TABLE myTable

 

Noting that the TRUNCATE statement automatically resets the counter.

Subscribe

  • follow us in feedly


Tagged .

Updated: 2011-09-01

Phil LaNasa