Cassandra - Syntex for Creating a Keyspace using Cqlsh Command

Cassandra - Syntex for Creating a Keyspace using Cqlsh Command

access_timeFriday, 4 May, 2018 chat_bubble_outline0 comments
Keyspace in Cassandra is similar to a Database or Schema in RDBMS. We can create tables within a keyspace.
 
The syntax for creating a Keyspace:-
 
CREATE KEYSPACE <identifier> WITH <properties> 
 
CREATE KEYSPACE “KeySpace Name”
WITH replication = {'class': ‘Strategy name’, 'replication_factor' : ‘No.Of  replicas’}
AND durable_writes = ‘Boolean value’;
 
The CREATE KEYSPACE statement has one identifier and two properties (replication and durable_writes).
 
Identifier:- identifier is just the name of the Keyspace.
 
Replication properties:- there are two types of replication 
 1) Simple Strategy:- In this replication strategy we specify a simple replication factor for the cluster.
 2) Network Topology Strategy:- In the Network Topology Replication Strategy you can set the replication factor for each datacenter independently.
 
Durable_writes properties:- By default the durable_writes properties of a table is true, we can set it to false.
 
Examples of creating the keyspace with different replication strategy and durable_writes properties.
 
1) Syntex for creating keyspace with "Simple Strategy"
 
CREATE KEYSPACE Players
WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1}
 
2) Syntex for creating keyspace with "Network Topology Strategy"
 
CREATE KEYSPACE Players
WITH replication = {'class':'NetworkTopologyStrategy', 'datacenter' : 3}
 
3) Syntex for creating keyspace with durable_writes properties
 
CREATE KEYSPACE Players
WITH replication = {'class':'NetworkTopologyStrategy', 'datacenter' : 3}
AND durable_writes = false;
 
After creation of a keyspace, you can check if it's created properly or not. for that the command is 
cqlsh> describe keyspace;
 
describe Keyspace command will list all the keyspace in the Cassandra DB.
 
Please share your suggestions and thoughts about this article in the comment box.
folder_openAssigned tags

0 Comments

Leave a Comment: