Cassandra Tutorial
Cassandra Keyspace
Cassandra Table Index
Cassandra Query (CQL)
Cassandra Collections
Cassandra Interview
Cassandra Update Data
UPDATE command is used to update data in a Cassandra table. If you see no result after updating the data, it means data is successfully updated otherwise an error will be returned. While updating data in Cassandra table, the following keywords are commonly used:
- Where: The WHERE clause is used to select the row that you want to update.
- Set: The SET clause is used to set the value.
- Must: It is used to include all the columns composing the primary key.
Syntax:
- UPDATE
- SET =
- = ....
- WHERE
Or
OOPs Concepts in Java
- Update KeyspaceName.TableName
- Set ColumnName1=new Column1Value,
- ColumnName2=new Column2Value,
- ColumnName3=new Column3Value,
- .
- .
- .
- Where ColumnName=ColumnValue
Note: When you use the UPDATE command and the given row is available, then UPDATE creates a fresh row.
Example:
Let's take an example to demonstrate how to update data in Cassandra table. We have a table named "student" with columns (student_id, student_fees student_name) having the following data:
Here, we update student_fees of student_id 2 to 10000 and student_name to Rahul.
- UPDATE student SET student_fees=10000,student_name='Rahul'
- WHERE student_id=2;
Now, the table is updated. You can verified it by using SELECT command.
- SELECT * FROM student;
Output: