TRUNCATE
Synopsis
The TRUNCATE
statement removes all rows from a specified table.
Syntax
Diagram
Grammar
truncate ::= TRUNCATE [ TABLE ] table_name;
Where
table_name
is an identifier (possibly qualified with a keyspace name).
Semantics
- An error is raised if the specified
table_name
does not exist.
Examples
Truncate a table
cqlsh:example> CREATE TABLE employees(department_id INT,
employee_id INT,
name TEXT,
PRIMARY KEY(department_id, employee_id));
cqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (1, 1, 'John');
cqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (1, 2, 'Jane');
cqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (2, 1, 'Joe');
cqlsh:example> SELECT * FROM employees;
department_id | employee_id | name
---------------+-------------+------
2 | 1 | Joe
1 | 1 | John
1 | 2 | Jane
Remove all rows from the table.
cqlsh:example> TRUNCATE employees;
cqlsh:example> SELECT * FROM employees;
department_id | employee_id | name
---------------+-------------+------
See also
当前内容版权归 YugabyteDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 YugabyteDB .