CQL has many commands. Let’s insert some rows of data into our newly created ‘users’ table with an INSERT INTO command.
Type ENTER after each statement to insert the row into the table:
cqlsh> INSERT INTO users (firstname, lastname, age, email, city) VALUES (‘John’, ‘Smith’, 46, ‘firstname.lastname@example.org’, ‘Sacramento’);
cqlsh> INSERT INTO users (firstname, lastname, age, email, city) VALUES (‘Jane’, ‘Doe’, 36, ‘email@example.com’, ‘Beverly Hills’);
cqlsh> INSERT INTO users (firstname, lastname, age, email, city) VALUES (‘Rob’, ‘Byrne’, 24, ‘firstname.lastname@example.org’, ‘San Diego’);
Now that we have a few rows of data in our table, let’s perform some queries against it. Using a SELECT statement will let us take a peek inside our table. To see all the rows from the users table we’ve created, type:
cqlsh:demo> SELECT * FROM users;
You should see:
Cassandra allows you to look up rows by their primary key. Remember we set the the last name as the row key, or primary key in CQL terms. Primary key determines where the row is located on disk. When we use a WHERE clause with a SELECT statement, we can query the table by row key.
Get the user record for the individual with the last name “Doe”.
cqlsh:demo> SELECT * FROM users WHERE lastname= ‘Doe’;