DESCRIBE KEYSPACE;
CREATE KEYSPACE mytestapp WITH REPLICATION = { 'class' : 'org.apache.cassandra.locator.NetworkTopologyStrategy', 'dc-1': '1' } AND DURABLE_WRITES = true;
use mytestapp;
CREATE TABLE IF NOT EXISTS users_by_city ( userid uuid, first_name text, last_name text, email text, city text, address text, PRIMARY KEY ((city), email, userid));
INSERT INTO users_by_city (userid, first_name, last_name, email, city, address) VALUES (now(), 'vikas', 'kumar', '[email protected]', 'delhi', '110092');
INSERT INTO users_by_city (userid, first_name, last_name, email, city, address) VALUES (now(), 'rahul', 'singh', '[email protected]', 'mumbai', 'andheri east');
SELECT * from users_by_city;
city | email | userid | address | first_name | last_name
--------+----------------+--------------------------------------+--------------+------------+-----------
delhi | [email protected] | dfbea2b0-048b-11eb-8d4b-e7907aa277e7 | 110092 | vikas | kumar
mumbai | [email protected] | 029bf580-048c-11eb-8d4b-e7907aa277e7 | andheri east | rahul | singh
CREATE TABLE IF NOT EXISTS products ( productid uuid, product_name text, product_category text, product_description text, PRIMARY KEY ((product_category), productid));
INSERT INTO products (productid, product_name, product_category, product_description) VALUES (now(), 'monitor', 'computer', 'HP 32 inch FHD monitor');
INSERT INTO products (productid, product_name, product_category, product_description) VALUES (now(), 'Keyboard', 'computer accessories', 'Dell US full keyboard');
INSERT INTO products (productid, product_name, product_category, product_description) VALUES (now(), 'iphone 11', 'mobile', 'iphone 11 black color witrh 128 GB internal storage');
product_category | productid | product_description | product_name
----------------------+--------------------------------------+-----------------------------------------------------+--------------
computer | 55155d30-048f-11eb-8d4b-e7907aa277e7 | HP 32 inch FHD monitor | monitor
mobile | a8354570-048f-11eb-8d4b-e7907aa277e7 | iphone 11 black color witrh 128 GB internal storage | iphone 11
computer accessories | 75eea2a0-048f-11eb-8d4b-e7907aa277e7 | Dell US full keyboard | Keyboard
UPDATE products SET product_description = 'DELL wireless keyboard and mouse combo' WHERE product_category = 'computer accessories' and productid= 75eea2a0-048f-11eb-8d4b-e7907aa277e7;
SELECT * FROM products WHERE product_category = 'computer accessories' AND productid = 75eea2a0-048f-11eb-8d4b-e7907aa277e7;
product_category | productid | product_description | product_name
----------------------+--------------------------------------+----------------------------------------+--------------
computer accessories | 75eea2a0-048f-11eb-8d4b-e7907aa277e7 | DELL wireless keyboard and mouse combo | Keyboard
DELETE FROM products WHERE product_category = 'computer accessories' AND productid = 75eea2a0-048f-11eb-8d4b-e7907aa277e7;
SELECT * FROM products;
product_category | productid | product_description | product_name
------------------+--------------------------------------+-----------------------------------------------------+--------------
computer | 55155d30-048f-11eb-8d4b-e7907aa277e7 | HP 32 inch FHD monitor | monitor
mobile | a8354570-048f-11eb-8d4b-e7907aa277e7 | iphone 11 black color witrh 128 GB internal storage | iphone 11