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
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Static type using batch in Cassandra
- Overview of User Defined Type (UDT) in Cassandra
- Collection Data Type in Apache Cassandra
- Pre-defined data type in Apache Cassandra
- Tuple Type in Cassandra
- Altering a table to add a collection data type in Cassandra
- Updating MAP collection data type in Cassandra
- Counter Type in Cassandra
- Role of keys in Cassandra
- High Availability Mechanism in Cassandra
- Apache Cassandra tools
- Blob conversion function in Cassandra
- Designing models in Cassandra
- Introduction to Apache Cassandra
- Apache Cassandra (NOSQL database)
- Architecture of Apache Cassandra
- Overview of Data modeling in Apache Cassandra
- Concept of indexing in Apache Cassandra
- Monitoring cluster in Cassandra
- Virtual machine installation for Cassandra CQL query
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.