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:
TRUNCATE TABLE `tableName`;
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.