Getting Started with DDL statements of Cassandra Query Language

docx

School

Australian Institute of Business *

*We aren’t endorsed by this school

Course

615

Subject

Computer Science

Date

Nov 24, 2024

Type

docx

Pages

4

Uploaded by assessmentst

Report
Getting Started with DDL statements of Cassandra Query Language Shivayan Mukherjee , 2023-12-01 Article Overview In this tutorial, we'll learn the essential DDL concepts of Cassandra query language (CQL) and how to use them in practical world. If you are not at all familiar with Cassandra, recommend you to read the article, Cassandra Springboot Integration , before progressing further in this tutorial. The article in the link would help you understand the fundamental concepts of Cassandra and how to install Apache Cassandra in different environments. Pre-requisites for this tutorial Basic concepts of Cassandra Fundamental knowledge of SQL Apache Cassandra software Cassandra Query Language (CQL) commands A few CQL commands that you need to know. Keyspace The Keyspace in Cassandra is similar to a database in RDBMS. It is an outermost container of data that defines the replication strategy and other attributes especially for all the Keyspace tables. CREATE Keyspace The following command is used to create a new Keyspace. The ' replication_factor ' denotes number of instances of the Keyspace in a node cluster. However if its a standalone server and replication_factor is still provided in the query as shown below in the example, a warning message is thrown by the system. The basis syntax is:
CREATE KEYSPACE keyspace_name WITH replication = {‘ class ':' replication_strategy ', ‘replication_factor' : n }; The replication property is mandatory and must contain the ' class ' sub-option that defines the desired replication strategy class. SimpleStrategy and NetworkTopologyStrategy are the commonly used ones. While SimpleStrategy defines a replication factor for data to be spread across the entire cluster and is usually not an automatic choice for production use, NetworkTopologyStrategy is a production-ready replication strategy that sets the replication factor independently for each data-center. Example: CREATE KEYSPACE demo_keyspace WITH replication = { 'class' : 'SimpleStrategy' , 'replication_factor' : 3 }; DESCRIBE Keyspaces In CQL it is possible list all Keyspaces as well as to describe a specific Keyspace. Let us have a look at the both the scenarios below. This is the command to list all Keyspaces within a cluster. Describe keyspaces ; The following command describes a single Keyspace. Describe keyspace_name ;
ALTER Keyspace The ALTER keyword is used to modify the definition of an existing keyspace. As seen in the previous example, by default the ' durable_writes ' property is 'true'. We will change it to 'false'. Basic Syntax: ALTER KEYSPACE keyspace_name WITH REPLICATION = { ‘ class ' : replication_strategy_class, ‘replication_factor' : n } AND DURABLE_WRITES = boolean_value ; Example ALTER KEYSPACE demo_keyspace WITH REPLICATION = { 'class' : 'SimpleStrategy' , 'replication_factor' : 3 } AND DURABLE_WRITES = false ; USE Keyspace This command connects the client session to the given Keyspace. DROP Keyspace The following command is used to drop an existing Keyspace.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Basic Syntax DROP KEYSPACE keyspace_name ; 'demo_keypsace' is dropped and verified using the following commands. TABLE A Table in Cassandra resides within the Keyspace. Table comprises of several rows with each row uniquely identifiable from the other by a primary key. Attempting to create an already existing table will return an error unless the 'IF NOT EXISTS' clause is used