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 cqlsh (CQL shell), either standalone, in the Astra Portal, or as part of a separate Cassandra installation.
You can also use the CQL API with DataStax drivers.
-
Install cURL.
-
Create a database and set the environment variables for database ID, region, keyspace, and token. For more information, see Create a database.
-
In the Astra Portal, go to Databases, and then click your database’s name.
-
Click Connect.
-
Select your API.
-
For multi-region databases, select the region to connect to.
-
Follow the steps to get your application token and set up your environment variables.
-
Interact with CQL
Add and retrieve schema and data using CQL.
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 address:
UPDATE users_keyspace.users SET email = 'mookie.betts-new-email@gmail.com' WHERE firstname = 'Mookie' AND lastname = 'Betts';
Verify that the row has the updated email address:
SELECT * FROM users_keyspace.users WHERE firstname = 'Mookie';
Delete data
Delete the row using the primary key:
DELETE FROM users_keyspace.users WHERE firstname = 'Mookie' AND lastname = 'Betts';