Cassandra Query Language (CQL) for Astra DB quickstart
Because Astra DB Serverless is powered by Apache Cassandra®, you can use the Cassandra Query Language shell (cqlsh
) utility to issue CQL commands against your databases, including CQL queries, adding and retrieving the schema and data, and more.
Prerequisites
-
An active Astra account
-
An active Astra DB Serverless database
Connect to your database
You can use the embedded CQL shell, the standalone CQL shell, or a CQL driver. For more information, see the following:
Create a table
Create a table within your default_keyspace
to include user information, defining the primary key as firstname
and lastname
:
CREATE TABLE default_keyspace.users (
firstname text,
lastname text,
email text,
"favorite color" text,
PRIMARY KEY (firstname, lastname)
)
WITH CLUSTERING ORDER BY (lastname ASC);
Insert data
Add data about a user into your new users
table:
INSERT INTO default_keyspace.users (
firstname,
lastname,
email,
"favorite color"
)
VALUES (
'Mookie',
'Betts',
'mookie.betts@gmail.com',
'blue'
)
;
Retrieve data
Select all rows in the table:
SELECT * FROM default_keyspace.users;
Select a specific row using the primary key:
SELECT * FROM default_keyspace.users
WHERE firstname = 'Mookie' AND lastname = 'Betts';
Update data
Update a user’s email address:
UPDATE default_keyspace.users SET email = 'mookie.betts-new-email@gmail.com'
WHERE firstname = 'Mookie' AND lastname = 'Betts';
Verify the row has the updated email address:
SELECT * FROM default_keyspace.users
WHERE firstname = 'Mookie';
Delete data
Delete a specific row using the primary key:
DELETE FROM default_keyspace.users
WHERE firstname = 'Mookie' AND lastname = 'Betts';