How do I delete all data in a Cassandra column family?

I'm looking for a way to delete all of the rows from a given column family in cassandra.

This is the equivalent of TRUNCATE TABLE in SQL.


Solution 1:

You can use the truncate thrift call, or the TRUNCATE <table> command in CQL.

http://www.datastax.com/docs/1.0/references/cql/TRUNCATE

Solution 2:

You can also do this via Cassandra CQL.

$ cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.6 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> TRUNCATE my_keyspace.my_column_family;

Solution 3:

Its very simple in Astyanax. Just a Single Line statement

/* keyspace variable is Keyspace Type */
keyspace.truncateColumnFamily(ColumnFamilyName); 

Solution 4:

If you are using Hector it is easy as well:

cluster.truncate("our keyspace name here", "your column family name here");

Solution 5:

If you are using cqlsh, then you can either do it in 2 ways

  1. use keyspace; and then truncate column_family;
  2. truncate keyspace.column_family;

If you want to use DataStax Java driver, you can look at - http://www.datastax.com/drivers/java/1.0/com/datastax/driver/core/querybuilder/QueryBuilder.html or http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/querybuilder/Truncate.html

depending on your version.