Skip to content

Used Cassandra for the first time, and here is what i made out of it - Student Marks DB

Notifications You must be signed in to change notification settings

CortaCoder/DataStax_Cassandra_Intro_workout

Repository files navigation

DataStax_Cassandra_Intro_workout

Repository by CortaCoder aka Sri Chakra Raj

Used Cassandra for the first time, and here is what i made out of it - Student Marks DB
I have always had the difficulty of searching my marks through the list provided by my Institute
So i got an idea of using the DataBase provided by Cassandra after attending my first ever DBMS session with DataStax

Thanks A Lot for Giving the Opportunity DataStax!!! :)

Here's What I made

Creating a Table named "student_marks"

CREATE TABLE IF NOT EXISTS student_marks(
   ... studentid int,
   ... student_name text,
   ... math_marks decimal,
   ... science_marks decimal,
   ... PRIMARY KEY ((studentid),student_name));

Lets Insert some Data

I have some data of my classmates which i will be inserting,

INSERT INTO student_marks (studentid,student_name,math_marks,science_marks)
   ... VALUES (110,'Sam',86.3,75.6);
INSERT INTO student_marks (studentid,student_name,math_marks,science_marks)
   ... VALUES (112,'Sharan',88.5,87.6);
INSERT INTO student_marks (studentid,student_name,math_marks,science_marks)
   ... VALUES (113,'Shravan',92.8,98.6);
INSERT INTO student_marks (studentid,student_name,math_marks,science_marks)
   ... VALUES (114,'SriChakraRaj',93,98.9);
INSERT INTO student_marks (studentid,student_name,math_marks,science_marks)
   ... VALUES (117,'Sumanth',98.9,97.6);

We have to check whether the data has been inserted or not. Head to the next section.

Read the Table

SELECT * FROM student_marks;


The Insertion was successful !!!

Reading the marks of a particular student

Here i want to read the marks of "Sharan" from the table. So i use the unique partition key named studentid to extract the desired row.

SELECT * FROM student_marks WHERE studentid = 112


Displaying the record with studentid = 112

Delete a particular Record from Table

  • Before deleting ,i want to insert a data row
    INSERT INTO student_marks (studentid,student_name,math_marks,science_marks)
       ... VALUES (110,'Sampath',86.3,75.6);
    
  • Once I read the entire table, i find two rows with the same studentid So to delete one of them, i have to make use of the clustering column i.e. student_name which is a part of PRIMARY KEY


  • Deleting the duplicate row
    DELETE FROM student_marks
       ... WHERE studentid = 110 AND student_name = "Sampath";
    

    You can see that the record was deleted.

Update a particular record

I wish to update the science_marks of studentid = 110.

UPDATE student_marks SET science_marks = 85.8 WHERE studentid = 110 AND student_name = 'Sam' 


The Record Got Updated Yay!!!

Once again Thanks DataStax !!! loved your Session :)

Will surely use Cassandra for my future apps and works.

About

Used Cassandra for the first time, and here is what i made out of it - Student Marks DB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published