Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Cassandra: Delete all the rows from a table

Using ‘TRUNCATE’ command, you can delete all the rows from a table.

Syntax:
::= TRUNCATE ( TABLE | COLUMNFAMILY )?

Example:
TRUNCATE keyspaceName.tableName;

If you are already in the keyspace, then you can use the tableName directly.

TRUNCATE tableName;

cqlsh> CREATE KEYSPACE cassandratutorial WITH REPLICATION = 
... {
... 'class' : 'SimpleStrategy',
... 'replication_factor' : 1
... };
cqlsh>
cqlsh> CREATE TABLE IF NOT EXISTS cassandratutorial.employee (
... id INT PRIMARY KEY,
... firstName VARCHAR,
... lastName VARCHAR,
... age int
... );
cqlsh>
cqlsh> INSERT INTO cassandratutorial.employee JSON '{"id" : 1, "firstName" : "Krishna", "lastName" : "Gurram", "age" : 30}';
cqlsh> INSERT INTO cassandratutorial.employee JSON '{"id" : 2, "firstName" : "Ram", "lastName" : "Gurram", "age" : 31}' ;
cqlsh> INSERT INTO cassandratutorial.employee JSON '{"id" : 3, "firstName" : "Vijay", "lastName" : "Ponnam", "age" : 45}';
cqlsh> INSERT INTO cassandratutorial.employee JSON '{"id" : 4, "firstName" : "Chitra", "lastName" : "Rajan", "age" : 45}';
cqlsh>
cqlsh> SELECT * FROM cassandratutorial.employee;

id | age | firstname | lastname
----+-----+-----------+----------
1 | 30 | Krishna | Gurram
2 | 31 | Ram | Gurram
4 | 45 | Chitra | Rajan
3 | 45 | Vijay | Ponnam

(4 rows)
cqlsh>
cqlsh> TRUNCATE cassandratutorial.employee;
cqlsh>
cqlsh> SELECT * FROM cassandratutorial.employee;

id | age | firstname | lastname
----+-----+-----------+----------

(0 rows)



Previous                                                    Next                                                    Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Cassandra: Delete all the rows from a table

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×