Example of creating a keyspace

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

To query Apache Cassandra, create and use a keyspace. Choose an arbitrary data center name and register the name in the properties file of the snitch. Alternatively, in a cluster in a single data center, use the default data center name, for example, datacenter1, and skip registering the name in the properties file.


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