Locke Locke - 10 months ago 29
PHP Question

Delete all data from table but not the columns

How can I delete all the data in an SQL table, but not delete the columns? I want all the column names and attributes to still be there after the data is deleted.


You could either use:


From the MySQL docs:

TRUNCATE TABLE empties a table completely. Logically, this is equivalent to a DELETE statement that deletes all rows, but there are practical differences under some circumstances.

You could also use DELETE FROM tableName, but using TRUNCATE TABLE tableName is better because:

Truncate operations drop and re-create the table, which is much faster than deleting rows one by one, particularly for large tables.