TRUNCATE TABLE instantly removes all rows from one or more MariaDB tables and resets AUTO_INCREMENT counters.
TRUNCATE TABLE is faster than DELETE without a WHERE clause because it deallocates data pages rather than logging each row removal. It also resets AUTO_INCREMENT values, making it ideal for quickly purging staging or log tables.
Use TRUNCATE TABLE table_name;
to wipe every row. The command requires DROP privilege and cannot be rolled back unless the session is in --safe-rollback
mode with log-bin
disabled.
MariaDB allows truncating several tables in a single statement: TRUNCATE TABLE Orders, OrderItems;
performs an atomic truncate on both tables, maintaining referential integrity.
No. TRUNCATE TABLE always resets AUTO_INCREMENT to 1. If you must preserve the counter, use DELETE FROM table;
instead.
For partitioned tables, specify partitions: TRUNCATE TABLE Orders PARTITION (p2023_q1, p2023_q2);
. Only listed partitions are emptied; other partitions remain untouched.
Always disable foreign-key checks or truncate child tables first to avoid constraint errors. Schedule truncations during low-traffic windows and take backups when data recovery is critical.
Avoid truncating tables referenced by external replication tools or where point-in-time recovery is required. Use DELETE
with binlog enabled for auditable row-level changes.
No. It drops and recreates the table, so DELETE triggers do not execute. Use DELETE if trigger logic is required.
Yes. TRUNCATE is written to the binary log as DROP and CREATE statements, ensuring replicas also truncate.
Yes. Temporary tables can be truncated without affecting other sessions.