Database Reference
In-Depth Information
Tutorial Links
DataStax, a company that provides commercial support for Cassandra, offers a set of freely
available videos .
Example Code
The easiest way to interact with Cassandra is through its shell interface. You start the shell by
running bin/cqlsh from your install directory.
Then you need to create a keyspace. Keyspaces are similar to schemas in traditional relation-
al databases; they are a convenient way to organize your tables. A typical pattern is to use a
single different keyspace for each application:
CREATE
CREATE KEYSPACE field_guide
WITH
WITH REPLICATION = {
'class' : 'SimpleStrategy' , 'replication factor' : 3 } ;
USE field_guide ;
Now that you have a keyspace, you'll create a table within that keyspace to hold your re-
views. This table will have three columns and a primary key that consists of both the review-
er and the title, as that pair should be unique within the database:
CREATE
CREATE TABLE
TABLE reviews (
reviewer varchar ,
title varchar ,
rating int ,
PRIMARY
PRIMARY KEY
KEY ( reviewer , title ));
Once your table is created, you can insert a few reviews:
INSERT
INSERT INTO
INTO reviews ( reviewer , title , rating )
VALUES
VALUES ( 'Kevin' , 'Dune' , 10 );
INSERT
INSERT INTO
INTO reviews ( reviewer , title , rating )
VALUES
VALUES ( 'Marshall' , 'Dune' , 1 );
INSERT
INSERT INTO
INTO reviews ( reviewer , title , rating )
VALUES
VALUES ( 'Kevin' , 'Casablanca' , 5 );
Search WWH ::




Custom Search