(mysql.info.gz) TRUNCATE
Info Catalog
(mysql.info.gz) Subqueries
(mysql.info.gz) Data Manipulation
(mysql.info.gz) UPDATE
13.1.9 `TRUNCATE' Syntax
------------------------
TRUNCATE TABLE TBL_NAME
`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.
For `InnoDB' before version 5.0.3, `TRUNCATE TABLE' is mapped to
`DELETE', so there is no difference. Starting with MySQL/InnoDB-5.0.3,
fast `TRUNCATE TABLE' is available. The operation will still be mapped
to `DELETE' if there are foreign key constraints that reference the
table.
For other storage engines, `TRUNCATE TABLE' differs from `DELETE FROM'
in the following ways from MySQL 4.0 and up:
* Truncate operations drop and re-create the table, which is much
faster than deleting rows one by one.
* Truncate operations are not transaction-safe; you will get an
error if you have an active transaction or an active table lock.
* The number of deleted rows is not returned.
* As long as the table definition file `TBL_NAME.frm' is valid, the
table can be re-created as an empty table with `TRUNCATE TABLE',
even if the data or index files have become corrupted.
* The table handler does not remember the last used `AUTO_INCREMENT'
value, but starts counting from the beginning. This is true even
for `MyISAM' and `InnoDB', which normally does not reuse sequence
values.
In MySQL 3.23, `TRUNCATE TABLE' is mapped to `COMMIT; DELETE FROM
TBL_NAME', so it behaves like `DELETE'. `DELETE' DELETE.
`TRUNCATE TABLE' is an Oracle SQL extension. This statement was added
in MySQL 3.23.28, although from 3.23.28 to 3.23.32, the keyword `TABLE'
must be omitted.
Info Catalog
(mysql.info.gz) Subqueries
(mysql.info.gz) Data Manipulation
(mysql.info.gz) UPDATE
automatically generated byinfo2html