Sets a global consistency level and client-supplied timestamp for all columns written by the statements in the batch.
BEGIN BATCH
[ USING <write_option> [ AND <write_option> [...] ] ];
<dml_statement>
<dml_statement>
[...]
APPLY BATCH;
<write_option> is:
USING CONSISTENCY <consistency_level>
TIMESTAMP <integer>
A BATCH statement combines multiple data modification (DML) statements into a single logical operation. BATCH supports setting a client-supplied, global consistency level and timestamp that is used for each of the operations included in the batch.
You can specify these global options in the USING clause:
Batched statements default to a consistency level of ONE when unspecified.
After the USING clause, you can add only these DML statements:
Individual DML statements inside a BATCH cannot specify a consistency level or timestamp. These individual statements can specify a TTL (time to live). TTL columns are automatically marked as deleted (with a tombstone) after the requested amount of time has expired.
Close the batch statement with APPLY BATCH.
BATCH is not an analogue for SQL ACID transactions. Column updates are considered atomic and isolated within a given record (row) only.
BEGIN BATCH USING CONSISTENCY QUORUM
INSERT INTO users (userID, password, name) VALUES ('user2', 'ch@ngem3b', 'second user')
UPDATE users SET password = 'ps22dhds' WHERE userID = 'user2'
INSERT INTO users (userID, password) VALUES ('user3', 'ch@ngem3c')
DELETE name FROM users WHERE userID = 'user2'
INSERT INTO users (userID, password, name) VALUES ('user4', 'ch@ngem3c', 'Andrew')
APPLY BATCH;
| 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 |