Cassandra Hello World Example

Below article will show the example to connect to the Cassandra using Java Driver. 1) Create a Maven project in Eclipse IDE. 2) Click on Next button 3) Select Maven Archetype. For this one I have chosen maven-archetype-quickstart and click on Next button. Provide GroupID and ArtifactID and click on Finish button. 5) Add Cassandra […]

How to perform CRUD opearation on Cassandra using CQLSH

This article will show the useful commands to perform CRUD operation on Cassandra using CQLSH. 1) Insert the data Syntax is: insert into <TABLE_NAME>(COLUMN1, COLUMN2) values (VALUES1, VALUES2); The table structure to insert the data is: CREATE TABLE cassandrademo.users ( user_id int PRIMARY KEY, user_email text, user_name text, user_pwd text ) Use the following command […]

How to truncate a table in Cassandra using CQLSH

Syntax for truncating a table/columnfamily is : TRUNCATE <TABLE_NAME | COLUMN_FAMILY_NAME> Using this command will delete all the rows from the table/columnfamily. Let’s say the data in our table is: select * from users; Output: user_id | user_email | user_name | user_pwd ———+————–+———–+———- 1 | | user1 | pwd1 To truncate all the data […]

How to alter a table in Cassandra using CQLSH

Syntax for altering table/columnfamily is: ALTER TABLE <TABLENAME> <OPEARTION> or ALTER COLUMNFAMILY <TABLENAME> <OPEARTION> Below example is given for adding a column in the table. alter table cassandrademo.users add user_phone text; Verify the table structure by using: describe table users; Output: CREATE TABLE cassandrademo.users ( user_id int PRIMARY KEY, user_email text, user_name text, user_phone text, […]

How to create Columnfamilies or Tables in Cassandra using cqlsh

Syntax for creating a table/columnfamily is: CREATE TABLE <TABLE_NAME> ( ‘column-definition’, ‘column-definition’, ) (WITH <OPTION> AND <OPTION>) or CREATE COLUMNFAMILY <TABLE_NAME> ( ‘column-definition’, ‘column-definition’, ) (WITH <OPTION> AND <OPTION>) Syntax for defining a column in the table is: column_name column_data_type Example to create a table is given below: create table cassandrademo.users( user_id int Primary Key, […]

How to create Keyspace in Cassandra

In this example I am referring Cassandra 2.1.5 version Creating a keyspace Use the following to create a keyspace create keyspace cassand with replication={‘class’:’SimpleStrategy’, ‘replication_factor’:3} and durable_writes=true Here class attributes indicates the replication strategy. 3 types are strategies are applicable: Simple Strategy – Provides simple replication for the cluster. Network Topology Strategy – Each data-center […]


How to install DataStax DevCenter on MacOS for Cassandra

1) Go the dowload page of DataStax 2) Go bottom down the page and select DEVCENTER Visual Query Tool. 3) Select 64 bit for MacOS. It will start downloading. 4) Extract the file contents tar -xzvf Documents/DevCenter-1.3.1-macosx-x86_64.tar.gz 5) Go to the extracted folder and click on DevCenter icon to launch. 6) The DevCenter window […]