TRUNCATE
Removes all data from the specified table immediately and irreversibly.
Synopsis
TRUNCATE [ TABLE ] [<keyspace_name>.]<table_name> ;
| Syntax conventions | Description |
|---|---|
UPPERCASE |
Literal keyword. |
Lowercase |
Not literal. |
|
Variable value. Replace with a user-defined value. |
|
Optional.
Square brackets ( |
|
Group.
Parentheses ( |
|
Or.
A vertical bar ( |
|
Repeatable.
An ellipsis ( |
|
Single quotation ( |
|
Map collection.
Braces ( |
|
Set, list, map, or tuple.
Angle brackets ( |
|
End CQL statement.
A semicolon ( |
|
Separate the command line options from the command arguments with two hyphens ( |
|
Search CQL only: Single quotation marks ( |
|
Search CQL only: Identify the entity and literal value to overwrite the XML element in the schema and solrConfig files. |
Options
- TRUNCATE TABLE
-
The command to drop all rows from a table.
The short form is
TRUNCATE. - keyspace_name
-
Optional. Name of the keyspace containing the table to truncate. If not specified, the current keyspace is used.
- table_name
-
Name of the table to truncate.
|
On Linux systems, object names, such as keyspace and table names, are case-sensitive. CQL converts object names to lowercase unless enclosed in double quotation marks. |
Examples
-
Run the
TRUNCATEcommand with the name of the table to truncate:TRUNCATE country_flag;If you have multiple tables with the same name in different keyspaces, specify the keyspace to avoid ambiguity:
TRUNCATE cycling.country_flag; -
If needed, wait for the
TRUNCATEoperation to complete on all nodes.Because
TRUNCATEwaits for a response from all nodes, it can take some time to complete in clusters with slow nodes, many nodes, or geographically distant datacenters. -
Use a
SELECTstatement to verify that the table is empty.SELECT * FROM cycling.country_flag;country | cyclist_name | flag ---------+--------------+------ (0 rows)