How do I clear all the entries from just one table in MySQL with PHP?
+8
A:
TRUNCATE TABLE tablename
or
DELETE FROM tablename
The first one is usually the better choice, as DELETE FROM is slow on InnoDB.
Actually, wasn't this already answered in your other question?
R. Bemrose
2009-04-07 14:24:31
And from a requirement perspective, truncate will reset the indicies whereas delete won't.
Kezzer
2009-04-07 14:48:29
+1
A:
TRUNCATE TABLE table;
is the SQL command. In PHP, you'd use:
mysql_query('TRUNCATE TABLE table;');
cookiecaper
2009-04-07 14:26:20
+2
A:
TRUNCATE TABLE `table`
unless you need to preserve the current value of the AUTO_INCREMENT sequence, in which case you'd probably prefer
DELETE FROM `table`
though if the time of the operation matters, saving the AUTO_INCREMENT value, truncating the table, and then restoring the value using
ALTER TABLE `table` AUTO_INCREMENT = value
will happen a lot faster.
chaos
2009-04-07 14:46:54