Skip to content

Instantly share code, notes, and snippets.

@erangaeb
Last active March 2, 2016 06:25
Show Gist options
  • Save erangaeb/6cc28920c197a03024f7 to your computer and use it in GitHub Desktop.
Save erangaeb/6cc28920c197a03024f7 to your computer and use it in GitHub Desktop.
Cassandra cqlsh
# create keyspace
create keyspace senz with replication = {'class':'SimpleStrategy','replication_factor':1};
# list all keyspaces
describe keyspaces;
# drop keyspace
drop keyspace <name>;
drop keyspace senz;
# use keyspace
use senz;
# show tables in a keyspace
describe tables;
describe COLUMNFAMILIES;
# create table
CREATE TABLE user(id INT PRIMARY KEY, username TEXT, address TEXT);
# insert to table
INSERT INTO user(id, username, address) VALUES(1, 'eranga', 'colombo 03');
# select with partition key
SELECT * from user where id = 1;
# create secondary index
CREATE INDEX usernameIndex on user(username);
# select with secondary index
SELECT * from user where useranem = 'eranga';
# delete all query
TRUNCATE <table name>;
TRUNCATE user;
# view/describe table strcuture
describe <table name>;
describe user;
# drop table
drop table <table name>;
drop table user;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment