C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Cassandra Create KeyspaceCassandra 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: CREATE KEYSPACE <identifier> WITH <properties> Or Create keyspace KeyspaceName with replicaton={'class':strategy name, 'replication_factor': No of replications on different nodes} Different components of Cassandra KeyspaceStrategy: There are two types of strategy declaration in Cassandra syntax:
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 "TheDeveloperBlog". CREATE KEYSPACE TheDeveloperBlog WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3}; 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. There is another property of CREATE KEYSPACE in Cassandra. Durable_writesBy 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. CREATE KEYSPACE sssit WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 3 } AND DURABLE_WRITES = false; 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. Using a KeyspaceTo use the created keyspace, you have to use the USE command. Syntax: USE <identifier> See this example: Here, we are using TheDeveloperBlog keyspace.
Next TopicCassandra alter keyspace
|