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

  • RSS Feed for Posts


This entry was tagged .

Updated: 2011-09-01

Phil LaNasa

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">