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.
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);
Here, Employee bank change new will finally updted 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;
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
- Static type using batch in Cassandra
- Tuple Type in Cassandra
- Counter Type in Cassandra
- Overview of User Defined Type (UDT) in Cassandra
- Pre-defined data type in Apache Cassandra
- Collection Data Type in Apache Cassandra
- Updating MAP collection data type in Cassandra
- Altering a table to add a collection data type in Cassandra
- Snitches in Cassandra
- Updating Set in Cassandra
- Features of Cassandra
- CAST function in Cassandra
- Role of keys in Cassandra
- Monitoring cluster in Cassandra
- Lightweight Transactions in Cassandra
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.