Updating Set in Cassandra
Last Updated :
12 Jul, 2025
In this article, we will discuss how we can update set
Collection Data Type in different ways also we will discuss how we can insert rows by using the UPDATE clause and if we don’t want any set elements then we can also remove using UPDATE clause with (–) operator.
First, we will create table Food_menu in which Café_id, Order_Date, total_cost, Menu_items are the fields in the below-given table. Let’s have a look.
Create Table Food_menu
(
Cafe_id int Primary Key,
Order_Date Date,
total_cost int,
Menu_items Set<text>
);
Now, we are going to insert some data into the Food_menu table by using the following
Cassandra Query Language (CQL) query given below. Let’s have a look.
INSERT INTO Food_menu (Cafe_id, Order_Date, total_cost, Menu_items)
VALUES (7801, '2019-02-13', 500, {'Banana', 'Mango', 'Apple'});
INSERT INTO Food_menu (Cafe_id, Order_Date, total_cost, Menu_items)
VALUES (7802, '2019-02-15', 600, {'Banana', 'Mango', 'Apple'});
INSERT INTO Food_menu (Cafe_id, Order_Date, total_cost, Menu_items)
VALUES (7803, '2019-02-19', 800, {'grapes', 'papaya', 'pomegranate'});
Let's see the output of the inserted data.
select *
from Food_menu;
Output:

Now, here we will discuss the updating the set collection data type. Let’s have a look.
- We can add an element in set collection data type by using (+) operator.
UPDATE Food_menu
SET Menu_items = Menu_items + {'mango shake'}
WHERE Cafe_id = 7802;
Let's see the output of the above CQL query.
select *
from Food_menu;
Output:
- We can remove an element from a set by using subtraction (-) operator.
UPDATE Food_menu
SET Menu_items = Menu_items - { 'Banana'}
WHERE Cafe_id = 7801;
Let's see the output of the following above CQL query.
select *
from Food_menu;
Output:
- Now, if we want to remove all elements from a set then used the following CQL query given below.
UPDATE Food_menu
SET Menu_items = {''}
WHERE Cafe_id = 7803;
select *
from Food_menu;
Output:
Similar Reads
Updating a List in Cassandra In Cassandra list is a Collection Data Type. In this article, we will discuss how we can update a list in different ways such that we can add elements in the list at any position where we want. we can also append a list. Let's discuss one by one. Consider cluster1 is a keyspace. CREATE KEYSPACE clus
2 min read
Updating a List in Cassandra In Cassandra list is a Collection Data Type. In this article, we will discuss how we can update a list in different ways such that we can add elements in the list at any position where we want. we can also append a list. Let's discuss one by one. Consider cluster1 is a keyspace. CREATE KEYSPACE clus
2 min read
Updating a List in Cassandra In Cassandra list is a Collection Data Type. In this article, we will discuss how we can update a list in different ways such that we can add elements in the list at any position where we want. we can also append a list. Let's discuss one by one. Consider cluster1 is a keyspace. CREATE KEYSPACE clus
2 min read
Updating column's in Cassandra In this article, we will discuss how we can update the existing columns, how we can add a new column or drop a column in Cassandra, etc. Updating a column In Cassandra, to modify a column by executing an ALTER statement. Using ALTER table statement You can change the type of a column, Add a new colu
2 min read
Updating column's in Cassandra In this article, we will discuss how we can update the existing columns, how we can add a new column or drop a column in Cassandra, etc. Updating a column In Cassandra, to modify a column by executing an ALTER statement. Using ALTER table statement You can change the type of a column, Add a new colu
2 min read
Updating column's in Cassandra In this article, we will discuss how we can update the existing columns, how we can add a new column or drop a column in Cassandra, etc. Updating a column In Cassandra, to modify a column by executing an ALTER statement. Using ALTER table statement You can change the type of a column, Add a new colu
2 min read