MySQL TRUNCATE TABLE Statement: Delete All Rows Quickly
The 'TRUNCATE TABLE' statement in MySQL is used to remove all rows from a table. It's a powerful tool for quickly clearing out data, but it's important to understand its implications before using it.
Syntax:
TRUNCATE TABLE table_name;
Key Points:
- Removes All Rows: This statement deletes all existing data from the specified table. It's not a selective operation like the 'DELETE' statement.
- Resets Auto-Increment: The auto-increment counter for the table is reset to zero.
- Faster Than DELETE: 'TRUNCATE TABLE' is generally faster than 'DELETE' because it doesn't create transaction logs.
- Irreversible: The operation cannot be undone. Exercise caution before using 'TRUNCATE TABLE'.
- Requires DROP Privilege: You need the 'DROP' privilege on the table to execute this statement.
Example:
TRUNCATE TABLE employees;
This statement will remove all rows from the 'employees' table. Be sure you truly intend to delete all data before executing this command.
原文地址: https://www.cveoy.top/t/topic/lUZ5 著作权归作者所有。请勿转载和采集!