Open In App

Read and Write path in Cassandra

Prerequisites –

Write Path Execution in Cassandra :



Inserting Data :
In case of inserting data in Cassandra, we will create a keyspace and then create a table and then insert data into the table.

Example –



// Creating a keyspace
create keyspace UniersityData
replication = {'class': 'SimpleStrategy', 'replication_factor' : '3' };

// Creating a table and declaring the columns
create table CSE_Student(
student_id int,
name text,
email text,
primary key(student_id)
);

// Using the newly created keyspace
use UniersityData;

// Inserting values in the table for all the columns
Insert into CSE_student(student_id, name, email) 
values(012345, 'Ashish', 'ashish@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012346, 'Abi', 'abi@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012347, 'Rana', 'rana@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012348, 'Aayush', 'aayush@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012349, 'harsh', 'haarsh@gmail.com'); 


Read Path Execution :



Reading Data :
Write a cqlsh query to read data from CSE_student and give output for the same.

select * 
from CSE_student;

Output :

index student_id name email
0 12345 Ashish ashish@gmail.com
1 12346 Abi abi@gmail.com
2 12347 Rana rana@gmail.com
3 12348 Aayush aayush@gmail.com
4 12349 harsh haarsh@gmail.com

Article Tags :