Now, I’ll walk you thru some basic CRUD operations with Apache Cassandra 2.x Cassandra Query Language (CQL).
Create Keyspace:
- CREATE KEYSPACE CassandraCQLDemo
WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
Use existing keyspace:
- use CassandraCQLDemo;
Creating tables:
- CREATE TABLE users( user_id varchar, age int, email varchar, city varchar,PRIMARY KEY (user_id));
Insert records into table:
- INSERT INTO users(user_id, age, email, city)VALUES ('murali',32,'murali@example.com','Bangalore');
- INSERT INTO users(user_id, city) VALUES ('manjunath','Mangalore');
Read records from table:
- SELECT * FROM users;
- SELECT * FROM users WHERE user_id='murali';
Update existing record in a table:
- update users set email = ‘muralidharan@example.com’ where user_id='murali’;
Deleting records in table:
- DELETE email FROM users WHERE user_id = 'murali';
- DELETE FROM users WHERE user_id = 'manjunath';
Hope this helps someone.
No comments:
Post a Comment