Synopsis
Use the TRUNCATE
statement to remove 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
ycqlsh:example> CREATE TABLE employees(department_id INT,
employee_id INT,
name TEXT,
PRIMARY KEY(department_id, employee_id));
ycqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (1, 1, 'John');
ycqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (1, 2, 'Jane');
ycqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (2, 1, 'Joe');
ycqlsh:example> SELECT * FROM employees;
department_id | employee_id | name
---------------+-------------+------
2 | 1 | Joe
1 | 1 | John
1 | 2 | Jane
Remove all rows from the table.
ycqlsh:example> TRUNCATE employees;
ycqlsh:example> SELECT * FROM employees;
department_id | employee_id | name
---------------+-------------+------