Welcome to our SQL with Cassandra tutorial! In this lesson, we'll dive into the world of Cassandra, a powerful, scalable, and highly available NoSQL database management system. By the end of this tutorial, you'll be equipped to use Cassandra effectively in your projects. š”
Cassandra is an open-source, distributed database designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. It's a great choice for applications requiring scalability and fault tolerance.
To get started, let's install Cassandra on your machine. Follow the official documentation for installation instructions that best suit your operating system.
After installation, you can interact with Cassandra using the Cassandra Query Language (CQL) via the Cassandra Shell. To open the shell, navigate to the cassandra directory in your terminal and run:
bin/cqlshIn Cassandra, a keyspace represents a container for tables, while a table stores the data. Let's create a simple keyspace and table:
CREATE KEYSPACE my_keyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
USE my_keyspace;
CREATE TABLE users (
id UUID PRIMARY KEY,
name TEXT,
email TEXT,
age INT
);š” Pro Tip: Use the UUID data type for primary keys to ensure uniqueness across nodes.
Now, let's insert some data into the users table:
INSERT INTO users (id, name, email, age) VALUES (UUID(), 'John Doe', 'john.doe@example.com', 30);To retrieve data, you can use the SELECT statement:
SELECT * FROM users WHERE name = 'John Doe';To delete a row from the users table:
DELETE FROM users WHERE id = <your_user_id>;Cassandra uses a data model based on column families. This model is more flexible than traditional row-oriented databases, allowing for better performance with large datasets.
Cassandra clusters are managed using the Cassandra Operations Center (Cassandra Ops) or other tools like OpsCenter, DataStax OpsCenter, or Apache cassandra-tool.
What is the primary key data type used in Cassandra to ensure uniqueness?
That's it for our introductory SQL with Cassandra tutorial! In the next lessons, we'll delve deeper into more advanced topics like data modeling, data replication, and performance tuning. Stay tuned and happy learning! šŖ