Search⌘ K
AI Features

CQL DML: UPDATE statement

Explore how to perform updates on Apache Cassandra tables using the CQL UPDATE statement. Understand specifying primary keys in the WHERE clause, setting non-primary key columns, and applying timestamps and TTLs. Learn to use conditional updates with IF and IF EXISTS clauses, and grasp the implications of Cassandra’s write time behavior to manage data effectively.

We'll cover the following...

In this lesson, we will focus on the Data Manipulation Language (DML) UPDATE operations supported by Apache Cassandra.

The UPDATE statement

The UPDATE statement is used to write data in one or more columns of a given row. To identify the row for updation, values for all primary key columns for the table must be specified in the WHERE clause. Values of primary key columns cannot be updated. Values for one or more non-primary key columns are assigned using the SET keyword. If the row is non-existent, it is created. Otherwise, it is updated with the data provided. It cannot be known if the UPDATE statement resulted in an insert or an update.

MySQL
UPDATE table_name 
[ USING [TIMESTAMP timestamp_value] ('AND')* [TTL ttl_value] ]
SET
column_name = column_value ( ',' column_name = column_value )*
WHERE PK_column_name = PK_column_value ('AND' PK_column_name = PK_column_value )*
[ IF EXISTS | (IF condition (AND condition)*) ]
;

Please refer to syntax conventions for CQL syntax notation details.

For example, the following statement updates the record with id: ...