Curriculum
Cassandra is a distributed NoSQL database that allows for flexible and scalable data modeling. One of the key features of Cassandra is its support for a wide range of data types that can be used to model various types of data structures. In this tutorial, we will discuss the different data types supported by Cassandra and provide examples of their usage.
Data Types in Cassandra
Cassandra supports several data types, including:
Examples of Data Types in Cassandra
Let’s look at some examples of using the different data types in Cassandra.
Example 1: Using the Text Data Type
CREATE TABLE users ( id UUID PRIMARY KEY, name TEXT, email TEXT, created_at TIMESTAMP );
This example creates a table named users
with four columns: id
, name
, email
, and created_at
. The name
and email
columns are of the TEXT
data type, which allows for variable-length character strings.
Example 2: Inserting data into the table
INSERT INTO users (id, name, email, created_at) VALUES (550e8400-e29b-41d4-a716-446655440000, 'John Doe', '[email protected]', 1495473283145);
This example inserts a row into the users
table with the values for each column specified. The created_at
column is of the TIMESTAMP
data type.
Example 3: Retrieving data from the table
SELECT * FROM users;
This example retrieves all rows from the users
table.
Example 4: Using the List Data Type