Javatpoint Logo
Javatpoint Logo

Cassandra Create Keyspace

Cassandra Query Language (CQL) facilitates developers to communicate with Cassandra. The syntax of Cassandra query language is very similar to SQL.


What is Keyspace?

A keyspace is an object that is used to hold column families, user defined types. A keyspace is like RDBMS database which contains column families, indexes, user defined types, data center awareness, strategy used in keyspace, replication factor, etc.

In Cassandra, "Create Keyspace" command is used to create keyspace.

Syntax:

Or


Different components of Cassandra Keyspace

Strategy: There are two types of strategy declaration in Cassandra syntax:

  • Simple Strategy: Simple strategy is used in the case of one data center. In this strategy, the first replica is placed on the selected node and the remaining nodes are placed in clockwise direction in the ring without considering rack or node location.

  • Network Topology Strategy: This strategy is used in the case of more than one data centers. In this strategy, you have to provide replication factor for each data center separately.

Replication Factor: Replication factor is the number of replicas of data placed on different nodes. More than two replication factor are good to attain no single point of failure. So, 3 is good replication factor.

Example:

Let's take an example to create a keyspace named "javatpoint".

Cassandra Create keyspace 1

Keyspace is created now.

Verification:

To check whether the keyspace is created or not, use the "DESCRIBE" command. By using this command you can see all the keyspaces that are created.

Cassandra Create keyspace 2

There is another property of CREATE KEYSPACE in Cassandra.


Durable_writes

By default, the durable_writes properties of a table is set to true, you can also set this property to false. But, this property cannot be set to simplex strategy.

Example:

Let's take an example to see the usage of durable_write property.

Cassandra Create keyspace 3

Verification:

To check whether the keyspace is created or not, use the "DESCRIBE" command. By using this command you can see all the keyspaces that are created.

Cassandra Create keyspace 4

Using a Keyspace

To use the created keyspace, you have to use the USE command.

Syntax:

See this example:

Here, we are using javatpoint keyspace.

Cassandra Create keyspace 5




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA