TRUNCATE
Synopsis
Use the TRUNCATE
statement to clear all rows in a table.
Syntax
truncate ::= TRUNCATE [ TABLE ] { { [ ONLY ] name [ * ] } [ , ... ] }
truncate
Semantics
truncate
TRUNCATE [ TABLE ] { { [ ONLY ] name [ * ] } [ , … ] }
name
Specify the name of the table to be truncated.
TRUNCATE
acquiresACCESS EXCLUSIVE
lock on the tables to be truncated. TheACCESS EXCLUSIVE
locking option is not yet fully supported.TRUNCATE
is not supported for foreign tables.
Examples
yugabyte=# CREATE TABLE sample(k1 int, k2 int, v1 int, v2 text, PRIMARY KEY (k1, k2));
yugabyte=# INSERT INTO sample VALUES (1, 2.0, 3, 'a'), (2, 3.0, 4, 'b'), (3, 4.0, 5, 'c');
yugabyte=# SELECT * FROM sample ORDER BY k1;
k1 | k2 | v1 | v2
----+----+----+----
1 | 2 | 3 | a
2 | 3 | 4 | b
3 | 4 | 5 | c
(3 rows)
yugabyte=# TRUNCATE sample;
yugabyte=# SELECT * FROM sample;
k1 | k2 | v1 | v2
----+----+----+----
(0 rows)
当前内容版权归 YugabyteDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 YugabyteDB .