In this article, we will discuss a static column in which we will able to understand how the static column is useful and what is the actual role. Let’s have a look.
Static column:
In Cassandra Query Language (CQL) it is a special column that is shared by all the rows of a partition. the static column is very useful when we want to share a column with a single value.
In Cassandra query language static columns are only static within a given partition. The static column uses clustering columns and non-clustering column to declare the static column in table definition.
Let's understand with an example.
Now, first, we are going to define the static column in a table.
create table bank_emp_record
(
Name text,
bank_name text static,
Id int,
primary key(Name, Id)
);
Now, we are going to insert data into the bank_emp_record table.
Insert into bank_emp_record(Name, bank_name, Id)
values('Ashish', 'Employee bank', 101);
Insert into bank_emp_record(Name, bank_name, Id)
values('Ashish', 'Employee bank change', 102);
Insert into bank_emp_record(Name, bank_name, Id)
values('Ashish', 'Employee bank change new', 103);
Output:
Here, Employee bank change new will finally updated and shared column value to the same static column.
Now, let's consider if I don't insert any value for bank_name then by default it will share the same value. let's have a look.
BEGIN BATCH
Insert into bank_emp_record(Name, Id)
values('Ashish', 104);
Insert into bank_emp_record(Name, Id)
values('Ashish', 105);
APPLY BATCH;
In the above-given CQL query, we are using the BATCH statement to insert more rows in a table. Now, let see the final output of the table.
select *
from bank_emp_record;
Output:
To know about the restriction please follow the link given below to know what type of restriction when we create the static column and how we can use that properly Reference : DataStax
Similar Reads
Static type using batch in Cassandra Prerequisite - Cassandra In this article, we will discuss the static column using the BATCH statement and how it works with the BATCH statement. Static column can be used for conditional update using a batch statement. Letâs have a look. Let's consider bank_emp_details is a table name and Id, Name,
2 min read
Static type using batch in Cassandra Prerequisite - Cassandra In this article, we will discuss the static column using the BATCH statement and how it works with the BATCH statement. Static column can be used for conditional update using a batch statement. Letâs have a look. Let's consider bank_emp_details is a table name and Id, Name,
2 min read
Table Partitioning in Cassandra In this article, we are going to cover how we can our data access on the basis of partitioning and how we can store our data uniquely in a cluster. Let's discuss one by one. Pre-requisite â Data Distribution Table Partitioning : In table partitioning, data can be distributed on the basis of the part
2 min read
Operations on table in Cassandra In this article, we will discuss table operations like Create insert truncate drop in Cassandra with some sample exercise. Letâs have a look. Creating a table - Register: First, we are going to create a table namely as Register in which we have id, name, email, city are the fields. Letâs have a look
3 min read
Operations on table in Cassandra In this article, we will discuss table operations like Create insert truncate drop in Cassandra with some sample exercise. Letâs have a look. Creating a table - Register: First, we are going to create a table namely as Register in which we have id, name, email, city are the fields. Letâs have a look
3 min read
SSTable in Apache Cassandra In this article, we are going to discuss SSTable which is one of the storage engines in Cassandra and SSTable components and also, we will cover what type of information kept in different database file in SSTable. Letâs discuss one by one. SSTable : It is one of the storage engines in Apache Cassand
3 min read