TRUNCATE

Synopsis

The TRUNCATE statement removes all rows from a specified table.

Syntax

Diagram

TRUNCATE - 图1

Grammar

  1. 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

  1. cqlsh:example> CREATE TABLE employees(department_id INT,
  2. employee_id INT,
  3. name TEXT,
  4. PRIMARY KEY(department_id, employee_id));
  1. cqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (1, 1, 'John');
  1. cqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (1, 2, 'Jane');
  1. cqlsh:example> INSERT INTO employees(department_id, employee_id, name) VALUES (2, 1, 'Joe');
  1. cqlsh:example> SELECT * FROM employees;
  1. department_id | employee_id | name
  2. ---------------+-------------+------
  3. 2 | 1 | Joe
  4. 1 | 1 | John
  5. 1 | 2 | Jane

Remove all rows from the table.

  1. cqlsh:example> TRUNCATE employees;
  1. cqlsh:example> SELECT * FROM employees;
  1. department_id | employee_id | name
  2. ---------------+-------------+------

See also