cassandra
  1. cassandra-cql-delete-data

Cassandra Query (CQL) Delete Data

Cassandra Query Language (CQL) is a query language for Cassandra database. Delete operation in CQL is used to remove data from a table.

Syntax

The basic syntax for deleting data from a table in CQL is as follows:

DELETE FROM table_name
WHERE primary_key = value;

Here, we are specifying the table from which we want to delete the data. The WHERE clause is used to specify the condition that must be met in order to delete the data.

Example

Suppose we have a students table that contains information about students and their grades. We can use the following CQL query to delete a row from the table where the student_id is 1:

DELETE FROM students
WHERE student_id = 1;

Output

The delete operation in CQL does not return any output.

Explanation

The above example deletes a row from the students table where the student_id is 1. The WHERE clause is used to specify the condition for the row to be deleted. Only the rows that meet the condition will be deleted.

Use

The delete operation in CQL is useful in situations where we need to remove data from a table. This can be useful when we want to update our data or remove stale data.

Important Points

  • Be careful when performing delete operations as it can permanently remove data from the table.
  • Always specify the WHERE clause to prevent deleting all the data from the table.
  • Deleting data from a table can impact query performance if the number of deleted rows is large.

Summary

In this tutorial, we learned how to delete data from a table using CQL. We saw the basic syntax for deleting data and how to specify the WHERE clause to delete specific data from the table. We also discussed the use cases of delete operation in CQL and some important points to keep in mind when performing the delete operation.

Published on: