Some CQL 3 examples you can run from the Driver
Show all the Keyspaces:
SELECT * FROM system.schema_keyspaces
Create a Keyspace with replication factor 1:
CREATE KEYSPACE test WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': 1 }
Create a Sample table:
CREATE TABLE mytable (thekey text,col1 text,col2 text,PRIMARY KEY (thekey, col1))
Create a more complex table:
CREATE TABLE IF NOT EXISTS test (userid int, firstname text, lastname text, tele set<text>, emails set<text>, skills list<text>, todos map<timestamp,text>, PRIMARY KEY (userid) )
Insert simple:
INSERT INTO mytable (thekey, col1, col2) VALUES ('first', 'Carles Mateo', 'http://blog.carlesmateo.com')
Insert more complex:
INSERT INTO test (userid, firstname, lastname, tele, emails, skills, todos) VALUES (1, 'David', 'Lebrón', {'770-111-1111','770-222-2222'}, {'myemail@carlesmateo.com','yxie2@kennesaw.edu'}, ['carpenter','instructor'], {'2014-04-14':'project Cassandra Universal Driver'})
Select:
SELECT * FROM mytable
Administrative commands to use from cqlsh command line tool
DESCRIBE KEYSPACE Keyspace;
USE Keyspace;
To see the Tables in a KeySpace (after USE Keyspace):
DESCRIBE TABLES;
One thought on “CQL Sample Queries”