Adds or updates one or more columns in the identified row of a column family.
INSERT INTO [keyspace.]<column_family>
(<keyname>, <colname> [, ...]) VALUES
(<keyvalue>, <colvalue> [, ...])
[USING <consistency>
[AND TIMESTAMP <timestamp>]
[AND TTL <timetolive>]];
An INSERT writes one or more columns to a record in a Cassandra column family. No results are returned. The first column name in the INSERT list must be the name of the column family key. Also, there must be more than one column name specified (Cassandra rows are not considered to exist with only a key and no associated columns).
The first column value in the VALUES list is the row key value to insert. List column values in the same order as the column names are listed in the INSERT list. If a row or column does not exist, it will be inserted. If it does exist, it will be updated.
Unlike SQL, the semantics of INSERT and UPDATE are identical. In either case a record is created if none existed before, and updated when it does.
You can qualify column family names by keyspace. For example, to insert a column into the NerdMovies table in the oscar_winners keyspace:
INSERT INTO Hollywood.NerdMovies (user_uuid, fan)
VALUES ('cfd66ccc-d857-4e90-b1e5-df98a3d40cd6', 'johndoe')
Specifying Options
You can specify these options:
TTL columns are automatically marked as deleted (with a tombstone) after the requested amount of time has expired.
INSERT INTO Hollywood.NerdMovies (user_uuid, fan) VALUES ('cfd66ccc-d857-4e90-b1e5-df98a3d40cd6', 'johndoe') USING CONSISTENCY LOCAL_QUORUM AND TTL 86400;
INSERT INTO History.tweets (tweet_id, author, body) VALUES (1742, 'gwashington', 'I chopped down the cherry tree'); INSERT INTO History.timeline (user_id, tweet_id, author, body) VALUES ('gmason', 1765, 'phenry', 'Give me liberty or give me death');
| 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 |