TRUNCATE
This page documents the preview version (v2.23). Preview includes features under active development and is for development and testing only. For production, use the stable version (v2024.1). To learn more, see Versioning.
Synopsis
Use the TRUNCATE statement to remove all rows from a specified table.
Syntax
Diagram
Grammar
truncate ::= TRUNCATE [ TABLE ] table_name;
Where
table_nameis an identifier (possibly qualified with a keyspace name).
Semantics
- An error is raised if the specified
table_namedoes 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
---------------+-------------+------