To update data in a table in Cassandra, the UPDATE command is used.
Keywords: WHERE clause: Used to select the row to be updated. SET clause: Used to set the value. MUST clause: Used to include all the columns composing the primary key.
Syntax 1:
UPDATE <table_name> SET <column_name> = <new_value> <column_name> = <value>.... WHERE <condition> |
Syntax 2:
Update Keyspace_Name.Table_Name Set Column_Name1 = new Column1_Value, Column_Name2 = new Column2_Value, Column_Name3 = new Column3_Value, ... Where Column_Name = Column_Value |
Example: Employees table:
id name salary 1 Adi 50000 2 Bruno 30000 3 Chris 60000 4 Davis 20000 5 Eliza 15000
Query:
UPDATE employees SET salary = 20000 WHERE ID = 2; |
Explanation: In the above example, we are updating the value of the ‘salary’ column to 20000, where the value of ID is 2. Verify it by using the below command. SELECT * FROM employees;
Output:
id name salary 1 Adi 50000 2 Bruno 20000 3 Chris 60000 4 Davis 20000 5 Eliza 15000
Please follow and like us: