Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Cassandra Query Language (CQL) Commands
#1


Basic Cassandra Query Language (CQL) Commands



The following section will showcase Cassandra’s most popular basic CQL commands and provide some practical examples.


cqlsh
cqlsh, or Cassandra query language shell, is used to communicate with Cassandra and initiate Cassandra Query Language. To start cqlsh, use the following command:

root@myawesomevps:/# cqlsh
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.5 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh>

HELP
The HELP command lists out descriptions for all possible cqlsh commands:
CQLSH help
For example, the output for HELP SHOW would look like this:

cqlsh> HELP SHOW

        SHOW [cqlsh only]

Displays information about the current cqlsh session. Can be called in the following ways:

        SHOW VERSION

Shows the version and build of the connected Cassandra instance, as well as the version of the CQL spec that the connected Cassandra instance understands.

        SHOW HOST

Shows where cqlsh is currently connected.

        SHOW SESSION

Pretty-prints the requested tracing session.

cqlsh>

SHOW
The SHOW command displays all the information about the current cqlsh session. You can choose between showing host, version, and session information:

cqlsh> SHOW VERSION
[cqlsh 6.0.0 | Cassandra 4.0.5 | CQL spec 3.4.5 | Native protocol v5]

cqlsh> SHOW HOST
Connected to Test Cluster at 127.0.0.1:9042
cqlsh>

CREATE KEYSPACE
A keyspace specifies data replication. In the following example, we will create a new keyspace and specify the replication factor:

cqlsh> CREATE KEYSPACE testingout
  WITH REPLICATION = {
  'class' : 'SimpleStrategy',
  'replication_factor' : 1
  };

USE
The USE command sets the current working keyspace:

cqlsh> USE testingout;
cqlsh:testingout>

CREATE TABLE
In order to create a table, users need to use the CREATE TABLE command. Here they will need to specify column names, data types, and primary key:

cqlsh:testingout> CREATE TABLE tabletest (
                    name TEXT PRIMARY KEY,
                    surname TEXT,
                    phone INT
                  );

INSERT
INSERT command is used to add an entire row into a table. Mind that missing values will be set to null:

cqlsh:testingout> INSERT INTO tabletest (name, surname, phone) 
VALUES ('John', 'Johnson', 456123789);
cqlsh:testingout>





Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)