Category : Cassandra | Sub Category : Cassandra | By Prasad Bonam Last updated: 2023-08-19 19:17:41 Viewed : 44
How you can create a keyspace in Cassandra using the CQL :
Here is an example of how you can create a keyspace in Cassandra using the CQL (Cassandra Query Language):
cqlCREATE KEYSPACE my_keyspace WITH replication = {`class`: `SimpleStrategy` ,`replication_factor`: 3};
In this example:
my_keyspace
is the name of the keyspace you want to create. You can choose any name that suits your application.replication
specifies the replication options for the keyspace. In this case, we are using the SimpleStrategy
replication class, which places replicas in the cluster based on a replication factor. The replication_factor
parameter specifies how many copies of the data should be maintained. In this case, there will be three copies of the data spread across the cluster nodes.Remember that the replication strategy and factor should be chosen based on your applications requirements for availability, fault tolerance, and consistency.
After creating the keyspace, you can start using it by switching to it using the USE
statement:
cqlUSE my_keyspace;
All subsequent table and data operations will be performed within the context of the my_keyspace
keyspace.