Define a new keyspace and its replica placement strategy.
CREATE KEYSPACE <ks_name> WITH strategy_class = <value> [ AND strategy_options:<option> = <value> [...] [ AND durable_writes = true | false ] ];
CREATE KEYSPACE creates a top-level namespace and sets the replica placement strategy, associated replication factor options, and the durable writes option for the keyspace. Valid keyspace names are strings of alpha-numeric characters and underscores, and must begin with a letter. Enclose keyspace names in double quotation marks to preserve case-sensitive names; otherwise, Cassandra stores keyspace names in lowercase. As of Cassandra 1.1.6, you do not need to enclose the noncase-sensitive keyspace name, strategy, and option strings in single quotation marks. Properties such as replication strategy and count are specified during creation using the following accepted keyword arguments:
|strategy_class||Required. The name of the replica placement strategy for the new keyspace, such as SimpleStrategy and NetworkTopologyStrategy.|
|strategy_options||Optional. Additional arguments appended to the option name.|
|durable_writes||Optional. True or false. Use caution. See durable_writes.|
Use the strategy_options keyword, separated by a colon to specify a strategy option. For example, a strategy option of DC1 with a value of 1 would be specified as strategy_options:DC1 = 1; replication_factor for SimpleStrategy could be strategy_options:replication_factor=3.
To use the NetworkTopologyStrategy, you specify the number of replicas per data center in this format:
See About Keyspaces for more information.
Define a new keyspace using the simple replication strategy:
These examples work with pre-release CQL 3 in Cassandra 1.1.x. The syntax differs in the release version of CQL 3 in Cassandra 1.2 and later.
CREATE KEYSPACE History WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1;
Define the number of replicas for one data center using the network-aware replication strategy, NetworkTopologyStrategy:
CREATE KEYSPACE test WITH strategy_class = 'NetworkTopologyStrategy' AND strategy_options:"us-east" = 6;
Double quotation marks must be used to enclose the us-east data center name because it contains a hyphen.
For a multiple data center cluster, assuming you are using the PropertyFileSnitch and your data centers are named DC1 and DC2 in the cassandra-topology.properties file.:
CREATE KEYSPACE test2 WITH strategy_class = 'NetworkTopologyStrategy’ AND strategy_options:DC1 = 3 AND strategy_options:DC2 = 6;
Change the durable_writes attribute of a keyspace.
CREATE KEYSPACE test2 WITH strategy_class = NetworkTopologyStrategy AND strategy_options:DC1 = 3 AND durable_writes=false;
|CQL Commands||CQL Shell Commands|