Updates one or more columns in the identified row of a column family.
UPDATE <column_family>
[ USING <write_option> [ AND <write_option> [...] ] ];
SET <column_name> = <column_value> [, ...]
| <counter_column_name> = <counter_column_name> {+ | -} <integer>
WHERE <row_specification>;
<write_option> is:
CONSISTENCY <consistency_level>
TTL <seconds>
TIMESTAMP <integer>
``<row_specification>`` is:
<primary/composite key name> = <key_value>
<primary/composite key name> IN (<key_value> [,...])
An UPDATE writes one or more columns to a record in a Cassandra column family. No results are returned. Row/column records are created if they do not exist, or overwritten if they do exist.
A statement begins with the UPDATE keyword followed by a Cassandra column family name. To update multiple columns, separate the name/value pairs using commas.
The SET clause specifies the new column name/value pairs to update or insert. Separate multiple name/value pairs using commas. If the named column exists, its value is updated, otherwise, its value is inserted. To update a counter column value in a counter column family, specify a value to increment or decrement value the current value of the counter column.
Each update statement requires a precise set of row keys to be specified using a WHERE clause.
UPDATE Movies SET col1 = val1, col2 = val2 WHERE movieID = key1;
UPDATE Movies SET col3 = val3 WHERE movieID IN (key1, key2, key3);
UPDATE Movies SET col4 = 22 WHERE movieID = key4;
UPDATE NerdMovies USING CONSISTENCY ALL AND TTL 400
SET 'A 1194' = 'The Empire Strikes Back',
'B 1194' = 'Han Solo'
WHERE movieID = B70DE1D0-9908-4AE3-BE34-5573E5B09F14;
UPDATE UserActionCounts SET total = total + 2 WHERE keyalias = 523;
You can specify these options:
TTL columns are automatically marked as deleted (with a tombstone) after the requested amount of time has expired.
Update a column in several rows at once:
UPDATE users USING CONSISTENCY QUORUM
SET 'state' = 'TX'
WHERE user_uuid IN (88b8fd18-b1ed-4e96-bf79-4280797cba80,
06a8913c-c0d6-477c-937d-6c1b69a95d43,
bc108776-7cb5-477f-917d-869c12dfffa8);
Update several columns in a single row:
UPDATE users USING CONSISTENCY QUORUM
SET 'name' = 'John Smith', 'email' = 'jsmith@cassie.com'
WHERE user_uuid = 88b8fd18-b1ed-4e96-bf79-4280797cba80;
Update the value of a counter column:
UPDATE page_views USING CONSISTENCY QUORUM AND TIMESTAMP=1318452291034
SET 'index.html' = 'index.html' + 1
WHERE url_key = 'www.datastax.com';
| CQL Commands | CQL Shell Commands |
|---|---|
| ALTER TABLE | ASSUME |
| ALTER KEYSPACE | CAPTURE |
| BATCH | COPY |
| CREATE TABLE | DESCRIBE |
| CREATE INDEX | EXIT |
| CREATE KEYSPACE | SHOW |
| DELETE | SOURCE |
| DROP TABLE | |
| DROP INDEX | |
| DROP KEYSPACE | |
| INSERT | |
| SELECT | |
| TRUNCATE | |
| UPDATE | |
| USE |