CQL Delete Data

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Cassandra DELETE Data

DELETE command is used to delete data from Cassandra table. You can delete the complete table or a selected row by using this command.

Syntax:

  1. DELETE FROM <identifier> WHERE <condition>;   

Example:

Let's take an example to demonstrate how to delete data from Cassandra table. We have a table named "student" with columns (student_id, student_fees student_name), having the following data.

Cassandra Delete data 1


Delete an entire row

To delete the entire row of the student_id "3", use the following command:

  1. DELETE FROM student WHERE student_id=3;   

Cassandra Delete data 2

Row having student_id 3 has been deleted. You can verify it by using SELECT command.

Cassandra Delete data 3


Delete a specific column name

Example:

Delete the student_fees where student_id is 4.

  1. DELETE student_fees FROM student WHERE student_id=4;   

Cassandra Delete data 4

It is deleted now. You can verify it:

Cassandra Delete data 5

You can see that it is null now.