Cassandra
Cassandra Tutorial for Beginners: Learn in 3 Days
What is Apache Cassandra? Cassandra is a distributed database management system designed for...
In this article, you will learn-
Command 'Insert into' writes data in Cassandra columns in row form. It will store only those columns that are given by the user. You have to necessarily specify just the primary key column.
It will not take any space for not given values. No results are returned after insertion.
Syntax
Insert into KeyspaceName.TableName(ColumnName1, ColumnName2, ColumnName3 . . . .) values (Column1Value, Column2Value, Column3Value . . . .)
Example
Here is the snapshot of the executed command 'Insert into' that will insert one record in Cassandra table 'Student'.
Insert into University.Student(RollNo,Name,dept,Semester) values(2,'Michael','CS', 2);
After successful execution of the command 'Insert Into', one row will be inserted in the Cassandra table Student with RollNo 2, Name Michael, dept CS and Semester 2.
Here is the snapshot of the current database state.
Cassandra does upsert. Upsert means that Cassandra will insert a row if a primary key does not exist already otherwise if primary key already exists, it will update that row.
Command 'Update' is used to update the data in the Cassandra table. If no results are returned after updating data, it means data is successfully updated otherwise an error will be returned. Column values are changed in 'Set' clause while data is filtered with 'Where' clause.
Syntax
Update KeyspaceName.TableName
Set ColumnName1=new Column1Value,
ColumnName2=new Column2Value,
ColumnName3=new Column3Value,
.
.
.
Where ColumnName=ColumnValueExample
Here is the screenshot that shows the database state before updating data.
Here is the snapshot of the executed command 'Update' that update the record in the Student table.
Update University.Student Set name='Hayden' Where rollno=1;
After successful execution of the command 'Update Student', student name will be changed from 'Clark' to 'Hayden' that has rollno 1.
Here is the screenshot that shows the database state after updating data.
Command 'Delete' removes an entire row or some columns from the table Student. When data is deleted, it is not deleted from the table immediately. Instead deleted data is marked with a tombstone and are removed after compaction.
Syntax
Delete from KeyspaceName.TableName Where ColumnName1=ColumnValue
The above syntax will delete one or more rows depend upon data filtration in where clause.
Delete ColumnNames from KeyspaceName.TableName Where ColumnName1=ColumnValue
The above syntax will delete some columns from the table.
Example
Here is the snapshot that shows the current database state before deleting data.
Here is the snapshot of the command that will remove one row from the table Student.
Delete from University.Student where rollno=1;
After successful execution of the command 'Delete', one rows will be deleted from the table Student where rollno value is 1.
Here is the snapshot that shows the database state after deleting data.
There are following limitations in Cassandra query language (CQL).
Cassandra query language is not suitable for analytics purposes because it has so many limitations.
In Cassandra, data retrieval is a sensitive issue. The column is filtered in Cassandra by creating an index on non-primary key columns.
Syntax
Select ColumnNames from KeyspaceName.TableName Where ColumnName1=Column1Value AND ColumnName2=Column2Value AND . . .
Example
select * from University.Student;
Two records are retrieved from Student table.
Data is filtered by name column. All the records are retrieved that has name equal to gtupapers.
select * from University.Student where name='gtupapers';
What is Apache Cassandra? Cassandra is a distributed database management system designed for...
What is Cassandra Collections? Cassandra collections are a good way for handling tasks. Multiple...
Cassandra is designed to handle big data. Cassandra’s main feature is to store data on multiple...
Large organization such as Amazon, Facebook, etc. have a huge amounts of data to manage. So these...
There are two types of security in Apache Cassandra and Datastax enterprise. Internal...
The syntax of Cassandra query language (CQL) resembles with SQL language. Create Table Alter Table...