TRUNCATE
Removes all data from the specified table immediately and irreversibly, and removes all data from any materialized views derived from that table.
Synopsis
TRUNCATE [ TABLE ] [<keyspace_name>.]<table_name> ;
Syntax legend
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. |
Examples
To remove all data from a table without dropping the table:
-
If necessary, use the cqlsh CONSISTENCY command to set the consistency level to
ALL
. -
Use nodetool status or some other tool to make sure all nodes are up and receiving connections.
-
Use TRUNCATE or TRUNCATE TABLE, followed by the table name.
TRUNCATE cycling.country_flag;
-
Use SELECT to verify the table data has been truncated.
SELECT * FROM cycling.country_flag;
country | cyclist_name | flag ---------+--------------+------ (0 rows)
TRUNCATE sends a JMX command to all nodes to delete SSTables that hold the data from the specified table. If any of the nodes are down or do not respond, the command fails and outputs a message like the following:
|