Simple Primary key

In a basic primary key one column uses a column name as the partition key. In this case, the primary key consists of only the partition key. Only the primary key can be specified when retrieving data from the table.

CREATE KEYSPACE Employee
WITH REPLICATION = { 'class' : 'SimpleStrategy',
'replication_factor' : 1 };
USE Employee;
CREATE TABLE Employee_info ( 
Employee_id UUID PRIMARY KEY,
Emp_name text,
Emp_domain text
);

Role of Keys in Cassandra

In this article, we are going to discuss why keys are important and how they are work and different from relational databases. Keys are used for grouping and organizing data into columns and rows in the database, so let’s have a look.

There are many portioning keys available in Cassandra.

1. Simple Primary key
2. Composite key
3. Using a compound primary key

Let’s discuss the concept of partitioning keys one by one.

Similar Reads

Simple Primary key

In a basic primary key one column uses a column name as the partition key. In this case, the primary key consists of only the partition key. Only the primary key can be specified when retrieving data from the table....

Composite key

In Cassandra composite partition key, we can use for more sorted row with the help of key. Let’s take an example to understand. Below given Employee_name is a part of primary key which is called the composite partition key for Employee_info table....

Using a Compound Primary Key

Use a compound primary key to create multiple columns that you can use to query and return sorted results. Let’s take an example of Employee_info table where we will de-normalize the data. To create a table having a compound primary key, use two or more columns as the primary key. Let’s take an example which uses an additional clause WITH CLUSTERING ORDER BY to order the Employee_points in descending order....

Conclusion

In conclusion, keys play a multi-faceted role in Cassandra, affecting how data is distributed, query throughput, scalability and overall system performance. With careful thought and design of keys, you can optimize the performance and efficiency of your Cassandra database across different applications and usage cases....

Contact Us