Database Monsters of the World Connect! Virtual Conference | January 12-14
Register Now

Lab 2: Basic CQL Operations

8 min to complete

Lab 2: Basic CQL Operations

After seeing how to run a single Scylla instance in the last lab, and running the CQL Shell, in this lab, we will see how to run some basic CQL commands. We will work with our newly created Scylla instance to create a table, insert data into it, and read the data.

 

Let’s start by making sure our node is  still up:

docker exec -it scyllaU nodetool status

Run a CQL shell:

docker exec -it scyllaU cqlsh 

Create a keyspace called “mykeyspace”:

CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1};

Keep in mind that SimpleStrategy should not be used in production.

Next, create a table with three columns: user id, first name, and last name, and insert some data:

use mykeyspace; 
CREATE TABLE users ( user_id int, fname text, lname text, PRIMARY KEY((user_id))); 

Insert into the newly created table two rows:


insert into users(user_id, fname, lname) values (1, 'rick', 'sanchez'); 
insert into users(user_id, fname, lname) values (4, 'rust', 'cohle'); 

Read the table contents:

select * from users;

To summarize, we saw how easy it is to start a Scylla cluster and perform some basic CQL operations. In the next lessons, we will see some more advanced commands.

Read more about the CQL shell here.

fa-angle-up