Developing with CQL
To use the Cassandra Query Language (CQL) with Astra DB Classic you can use the same CQL syntax, tools and native language drivers that you would with a Apache Cassandra® deployment.
Prerequisites
-
Connect to the CQL shell or install a DataStax CQL driver.
-
Install cURL.
-
Create a database and set environment variables for the database ID, region, keyspace, and token. For more information, see Create a database.
Create a table
CREATE TABLE users_keyspace.users (
firstname text,
lastname text,
email text,
"favorite color" text,
PRIMARY KEY (firstname, lastname)
) WITH CLUSTERING ORDER BY (lastname ASC);
Insert data
INSERT INTO users_keyspace.users (
firstname,
lastname,
email,
"favorite color"
) VALUES (
'Mookie',
'Betts',
'mookie.betts@gmail.com',
'blue'
);
Retrieve data
To select all rows in the table:
SELECT * FROM users_keyspace.users;
To select a row using the primary key:
SELECT * FROM users_keyspace.users WHERE firstname = 'Mookie' AND lastname = 'Betts';
Update data
Update the email
column for a specific row:
UPDATE users_keyspace.users SET email = 'mookie.betts-new-email@gmail.com' WHERE firstname = 'Mookie' AND lastname = 'Betts';
Verify that the update was applied as expected:
SELECT * FROM users_keyspace.users WHERE firstname = 'Mookie';
Delete data
Delete a row using the primary key:
DELETE FROM users_keyspace.users WHERE firstname = 'Mookie' AND lastname = 'Betts';