The Cassandra Alter Command is used to change the configuration of the already created Keyspace. We can alter the replication factor, replication strategy, durable writes. We can't alter the name of the Keyspace.
Cassandra Alter Keyspace
We can use the following Alter command to make the configuration changes in a Keyspace.
Syntax:
ALTER keyspace keyspace_nameWITH options
Let's see an example to Alter the cloudduggu keyspace which was created in the Create Keyspace tutorial section. We will Alter the cloudduggu keyspace and change the class:NetworkTopologyStrategy from SimpleStrategy and replication_factor from 1 to 2.
Command:
cqlsh> describe cloudduggu;cqlsh> ALTER keyspace cloudduggu
... WITH REPLICATION = {'class':'NetworkTopologyStrategy', 'datacenter1' : 2 ,'replication_factor' : 2};
cqlsh> describe cloudduggu;
Output:
In the following output, we can see that first, we have used Describe Command to see the existing structure of Keyspace cloudduggu post that we have executed the Alter command to change the Class and the replication factor. Again we have executed the Describe Command to see those changes.