Home / Articles / Database / cassandra / 4.0.0 / insert-query

Insert and Query

Create Keyspace

    cqlsh> CREATE KEYSPACE IF NOT EXISTS store WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : '1' };

Create Table

    cqlsh> CREATE TABLE IF NOT EXISTS store.shopping_cart ( userid text PRIMARY KEY, item_count int, last_update_timestamp timestamp

Insert Record

    cqlsh> INSERT INTO store.shopping_cart (userid, item_count, last_update_timestamp) VALUES ('9876', 2, toTimeStamp(now())); INSERT INTO store.shopping_cart (userid, item_count, last_update_timestamp) VALUES ('1234', 5, toTimeStamp(now()));

Query Records

    cqlsh> SELECT * FROM store.shopping_cart; userid | item_count | last_update_timestamp --------+------------+--------------------------------- 1234 | 5 | 2021-08-21 19:36:34.358000+0000 9876 | 2 | 2021-08-21 19:36:33.449000+0000 (2 rows)