Till now, we have seen how to create a Cassandra keyspace, how to show all the tables of a keyspace, how to create a new table in keyspace and how to show structure of tables in a keyspace. In this particular article we will see, how to insert a record in Cassandra tables to store application table. We will use already created table ?student? to insert a few rows of data.

Insert a row in Cassandra Tables

Inserting a row in Cassandra is much like inserting a row in relational databases, here is a simple syntax.

cqlsh:tbNext> INSERT INTO student(stuID,deptID,first_name,last_name)

Unlike relational databases we can not insert a record without specifying columns, while try to run the insert query without specifying columns we will get following error:

cqlsh:tbNext> insert into student values(1,23,'Tech','Burps');
Bad Request: line 1:47 mismatched input ';' expecting K_VALUES

Now we have just added a new entry in student table, let?s see the data with a select query to the console.

SELECT * FROM student;

You will see following output with a newly inserted row in the table.

stuid | deptid | first_name | last_name
     1 |     23 |       Tech |     Burps

This is all about inserting data in Cassandra tables, In upcoming articles we will see more abour Cassandra and related No SQL technologies.
  • By Techburps.com
  • Mar 22, 2015
  • Cassandra