105

Is there a command to all the rows present in a cql table in cassandra like the one in sql?

delete from TABLE

Going by the documentation, I don't find any way to perform delete operation without a where condition.

DELETE col1 FROM SomeTable WHERE userID = 'some_key_value'; 
Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105

1 Answers1

188

To remove all rows from a CQL Table, you can use the TRUNCATE command:

TRUNCATE keyspace_name.table_name;

Or if you are already using the keyspace that contains your target table:

TRUNCATE table_name;

Important to note, but by default Cassandra creates a snapshot of the table just prior to TRUNCATE. Be sure to clean up old snapshots, or set auto_snapshot: false in your cassandra.yaml.

Aaron
  • 55,518
  • 11
  • 116
  • 132
  • 1
    How to delete all rows without creating snapshot and editing cassandra config ? – Vinigas Feb 26 '20 at 09:04
  • 1
    @Vinigas It's a little difficult with those restrictions, so deleting the SSTable files from the keyspace/table directory might be your only option. The safer path would probably be to `TRUNCATE` and then run a `nodetool clearsnapshot` afterward. – Aaron Feb 26 '20 at 13:47
  • I guess you could just describe table (copy the creation command), then drop table and create table... does it make sense? – Javi Mar 18 '22 at 13:16