Learn Cassandra Basics in 15 Minutes

Learn Cassandra Basics in 15 Minutes

This article helps to show you how to set up and learn Cassandra DB in your local machine and how to do insert, update, delete, and search in Cassandra Database.

Cassandra DB is also an open-source database that is provided by Apache. It can be categorized under the NoSQL (Not Only SQL) database. Comparing to other databases the Cassandra is a super fast and high-performance database and it is following the column-oriented database concept. It can be configured as a cluster and it is fault-tolerant. Cassandra uses a gossip protocol to communicate with other nodes in the cluster. Cassandra has used many famous companies like Facebook, Netflix and Twitter. Please follow the steps are given below.

Firstly, you have to download the Cassandra database.

Then go to the bin folder and open a new terminal and type Cassandra in the terminal.

Open a new terminal and type cqlsh.

Create a keyspace.

CREATE KEYSPACE IF NOT EXISTS mymovies_keyspace WITH replication = {'class':'SimpleStrategy','replication_factor':3};

Create a table.

CREATE TABLE IF NOT EXISTS mymovies_keyspace.movies (title varchar,year int, description varchar, rating varchar, PRIMARY KEY (title,year));

Then, Insert the data.

INSERT INTO mymovies_keyspace.movies (title,year,description,rating) VALUES ('Chasing Leberty',2004,'Romance','5');

INSERT INTO mymovies_keyspace.movies (title,year,description,rating) VALUES ('Fast Five',2012,'Action','4.5'); 

INSERT INTO mymovies_keyspace.movies (title,year,description,rating) VALUES ('Annabelle',2019,'Horror','4.0');

Search data.

SELECT * FROM mymovies_keyspace.movies WHERE title='Annabelle' AND year=2019;

Update data.

UPDATE mymovies_keyspace.movies SET rating='6.3' WHERE title='Annabelle' AND year=2019;

Finally, Delete the data.

DELETE FROM mymovies_keyspace.movies WHERE title='Annabelle' AND year=2019;

As a result of practicing this article you were able to Learn Cassandra Basics within 10-15 Minutes, you can get a better understanding referring my next article to create a simple java application with a Cassandra database.

To download Cassandra DB please visit here