Curriculum
Deleting data in Cassandra is an important operation that allows users to remove unwanted data from a table. In this tutorial, we will explore how to delete data in Cassandra, including its syntax and examples.
Syntax:
The basic syntax for deleting data in Cassandra is as follows:
DELETE FROM table_name WHERE column_name = value;
Where:
DELETE
is the keyword that specifies the delete operation.table_name
is the name of the table from which to delete data.column_name
is the name of the column that specifies the data to be deleted.value
is the value of the column that specifies the data to be deleted.Examples:
To illustrate how to delete data in Cassandra, we will use the following example table:
CREATE TABLE example_table ( id int, name text, age int, PRIMARY KEY (id) );
Now let’s insert some data into this table:
INSERT INTO example_table (id, name, age) VALUES (1, 'John', 25); INSERT INTO example_table (id, name, age) VALUES (2, 'Jane', 30); INSERT INTO example_table (id, name, age) VALUES (3, 'Bob', 40);
This will give us the following data in our table:
id | name | age ----+------+----- 1 | John | 25 2 | Jane | 30 3 | Bob | 40
Now, let’s delete the row with id
equal to 2:
DELETE FROM example_table WHERE id = 2;
This will delete the row with id
equal to 2, giving us the following data in our table:
id | name | age ----+------+----- 1 | John | 25 3 | Bob | 40
If we want to delete all rows in the table, we can use the following command:
TRUNCATE example_table;
This will remove all data from the table, leaving us with an empty table.
In this tutorial, we have explored how to delete data in Cassandra, including its syntax and examples. By following the examples in this tutorial, users should be able to easily delete unwanted data from their tables.