Tuesday 24 July 2018

Cassandra Update Data

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:
  1. UPDATE <tablename>  
  2. SET <column name> = <new value>  
  3. <column name> = <value>....  
  4. WHERE <condition>   
Or
  1. Update KeyspaceName.TableName   
  2. Set ColumnName1=new Column1Value,  
  3.       ColumnName2=new Column2Value,  
  4.       ColumnName3=new Column3Value,  
  5.        .  
  6.        .  
  7.        .  
  8. 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:
Cassandra Update data 1
Here, we update student_fees of student_id 2 to 10000 and student_name to Rahul.
  1. UPDATE student SET student_fees=10000,student_name='Rahul'  
  2. WHERE student_id=2;   
Cassandra Update data 2
Now, the table is updated. You can verified it by using SELECT command.
  1. SELECT * FROM student;   
Output:
Cassandra Update data 3

0 comments:

Post a Comment