WP-Mix

A fresh mix of code snippets and tutorials

Truncate Database Table

Quick SQL code snippet that enables you to truncate any MySQL database table.

Let’s say that your table name is wp_downloads. It contains thousands of rows and so you want to truncate the data to a more manageable size. To do so, execute the following SQL query (via phpMyAdmin or whatever works for you):

DELETE FROM `wp_downloads` ORDER BY `id` ASC LIMIT 500

Key points:

  • Instead of DELETE you can use TRUNCATE
  • ASC = ascending, means that oldest entries are deleted first
  • Remember to make a backup before trying this query. Just in case.
  • You can change the number of rows that are deleted by changing 500 to whatever number

Possibly Related

★ Pro Tip:

USP ProSAC Pro