How to Create INDEX in Cassandra

  1. Creating Table First

CREATE TABLE spoint.emp(
ID int ,
Name text Primary Key,
City text );

spoint is the keyspace and emp is table

2. Insert the Records inside the Table.

insert into emp (id,city,name) values (113,’cardiff’,’jason’);
insert into emp (id,city,name) values (114,’perth’,’mike’);
insert into emp (id,city,name) values (115,’miami’,’ronny’);
insert into emp (id,city,name) values (116,’california’,’sunny’);

using keyspace spoint and inserted the records

using “select id, city, name from emp” to Display all Records.

display all inserted records using Select Statement.

Filtering Records with “select * from emp where id=115”.

getting error because column id has no index and not set with primary key.

Create index IndexName on KeyspaceName.TableName(ColumnName);

Creating Index on ID Column ” Create index Idx on spoint.emp(id); “

Idx is the Index Name

Filtering the Records by “ select * from emp where id=115;

its filter the records without any error because column id set with index.

To Drop Index write : “drop index IF EXISTS spoint.Idx; “

droping query for index, spoint is keyspace and Idx is index name

Happy Query. Thanks!!!!!!!!!

Post Author: adama