Pacific-Design.com

    
Home Index

1. Cassandra

2. Examples

Cassandra / Examples /

Cassandra Examples


cqlsh>

#--- create a namespace ---#
CREATE KEYSPACE kevin WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
DESCRIBE KEYSPACES;
USE kevin;

#--- create a table ---#
CREATE TABLE user (
  id int PRIMARY KEY,
  first_name text,
  last_name text
);

#--- insert some data ---#
INSERT INTO user (id, first_name, last_name)  VALUES (1745, 'john', 'smith');
INSERT INTO user (id, first_name, last_name)  VALUES (1744, 'kevin', 'duraj');
INSERT INTO user (id, first_name, last_name)  VALUES (1746, 'thomas', 'smith');
SELECT * FROM user;



#--- create a secondary index ---#
CREATE INDEX ON user (last_name);

#--- search on secondary index ---#
SELECT * FROM user WHERE last_name = 'smith';