TRUNCATE TABLE
Updated at:
Copy as MD
Removes all rows from a table without logging individual row deletions.
Prerequisites
Before you begin, ensure that you have:
The
DROPprivilege on the target table
Syntax
TRUNCATE [TABLE] tbl_name| Parameter | Description |
|---|---|
TABLE | Optional keyword. TRUNCATE tbl_name and TRUNCATE TABLE tbl_name are equivalent. |
tbl_name | The name of the table to truncate. |
For the full syntax specification, see TRUNCATE TABLE statement.
Example
The following example truncates a table named orders and verifies the result.
-- Check the current row count
SELECT COUNT(*) FROM orders;
-- Result: 1000 rows
-- Truncate the table
TRUNCATE TABLE orders;
-- Verify the table is empty
SELECT COUNT(*) FROM orders;
-- Result: 0 rowsBehavior and limits
| Behavior | Description |
|---|---|
| Permissions | Requires the DROP privilege on the table. If you lack this privilege, the statement fails. |
See also
DELETE — Remove specific rows using a WHERE condition.
DROP TABLE — Remove the table and its structure entirely.
Is this page helpful?