Database Reference
In-Depth Information
WITH REPLICATION = {'class': 'NetworkTopologyStrategy',
'DC1': 3, 'DC2': 1}
# Keyspace with no durable writes
CREATE KEYSPACE IF NOT EXISTS demo_keyspace2
WITH REPLICATION = {'class': 'NetworkTopologyStrategy',
'DC1': 3, 'DC2': 1}
AND DURABLE_WRITES = 'false'
Note that class and replication_factor in the REPLICATION setting must be
in lowercase.
Altering a keyspace
You can alter keyspace properties like REPLICATION and DURABLE_WRITES , but the
names cannot be altered. Here is the CQL syntax for that:
ALTER {KEYSPACE | SCHEMA} keyspace_name
WITH {
REPLICATION = json_object |
DURABLE_WRITES = {true | false} |
REPLICATION = json_object AND DURABLE_WRITES = {true |
false}
}
Creating a table
Table creation in CQL3 is similar to how it's done in SQL. At the very least, you need to
specify the table name, the name and types of the columns, and the primary key. The
primary key can be single valued (made of a single column) or composite (made of more
than one column). For more detail on keys, refer to the A brief introduction to the data
model section in Chapter 1 , Quick Start . In the former case, the primary key works as a
partition key (or shard key). So, rows of such a table are distributed across the nodes
based on the hash value of the primary key. In the latter case, where primary key constitu-
tes of more than one column, the first column works as partition key. That means rows
with same partition key stay in one wide row. (Refer to the The column family section.)
This can be handy when you want to group things naturally. The following code snippet
can be used to create a table:
Search WWH ::




Custom Search