Skip to content

Latest commit

 

History

History
72 lines (50 loc) · 1.82 KB

sql-statement-truncate.md

File metadata and controls

72 lines (50 loc) · 1.82 KB
title summary aliases
TRUNCATE | TiDB SQL Statement Reference
An overview of the usage of TRUNCATE for the TiDB database.
/docs/dev/sql-statements/sql-statement-truncate/
/docs/dev/reference/sql/statements/truncate/

TRUNCATE

The TRUNCATE statement removes all data from the table in a non-transactional way. TRUNCATE can be thought of as semantically the same as DROP TABLE + CREATE TABLE with the previous definition.

Both TRUNCATE TABLE tableName and TRUNCATE tableName are valid syntax.

Synopsis

TruncateTableStmt:

TruncateTableStmt

OptTable:

OptTable

TableName:

TableName

Examples

mysql> CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY);
Query OK, 0 rows affected (0.11 sec)

mysql> INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM t1;
+---+
| a |
+---+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+---+
5 rows in set (0.00 sec)

mysql> TRUNCATE t1;
Query OK, 0 rows affected (0.11 sec)

mysql> SELECT * FROM t1;
Empty set (0.00 sec)

mysql> INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> TRUNCATE TABLE t1;
Query OK, 0 rows affected (0.11 sec)

MySQL compatibility

The TRUNCATE statement in TiDB is fully compatible with MySQL. If you find any compatibility differences, report them via an issue on GitHub.

See also