Example of creating a keyspace

A simple example of querying Cassandra by creating a keyspace and then using it.

To query Cassandra, you first create and use a keyspace. In this example, dc1 is the name of a data center that has been registered in the properties file of the snitch. To use NetworkTopologyStrategy for a cluster in a single data center, there is no need to register the data center name in the properties file. Simply use the default data center name, for example datacenter1.

Procedure

  1. Create a keyspace.
    cqlsh> CREATE KEYSPACE demodb
             WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 3 };
  2. Use the keyspace.
    USE demodb;