SlideShare a Scribd company logo
1 of 10
********************************************************************************
*****************************************************
CASSANDRA BASICS - SHELL COMMANDS
********************************************************************************
*****************************************************
HELP:
====
Displays help topics for all cqlsh commands.
Ex:
--
HELP
--------------------------------------------------------------------------------
----------------------------------------------------
CAPTURE:
=======
Captures the output of a command and adds it to a file.
Ex:
--
CAPTURE '/home/hadoop/CassandraProgs/Outputfile';
verification:
------------
CAPTURE '/home/hadoop/CassandraProgs/Outputfile';
select * from emp;
CAPTURE OFF;
--------------------------------------------------------------------------------
----------------------------------------------------
CONSISTENCY:
===========
Shows the current consistency level, or sets a new consistency level.
Ex:
--
CONSISTENCY
--------------------------------------------------------------------------------
----------------------------------------------------
COPY:
====
Copies data to and from Cassandra.
Ex:
--
COPY emp (emp_id, emp_city, emp_name, emp_phone, emp_sal) TO ‘myfile‘;
--------------------------------------------------------------------------------
----------------------------------------------------
DESCRIBE:
=========
Describes the current cluster of Cassandra and its objects.
Ex:
--
DESCRIBE CLUSTER;
DESCRIBE KEYSPACES;
DESCRIBE TABLES;
DESCRIBE TABLE emp;
DESCRIBE COLUMNFAMILIES;
DESCRIBE TYPES;
DESCRIBE TYPE card_details;
--------------------------------------------------------------------------------
----------------------------------------------------
EXPAND:
======
Expands the output of a query vertically.
Ex
--
EXPAND ON
EXPAND OFF
verificarion:
------------
EXPAND ON
select * from emp;
EXPAND OFF
--------------------------------------------------------------------------------
----------------------------------------------------
EXIT:
====
Using this command, you can terminate cqlsh.
--------------------------------------------------------------------------------
----------------------------------------------------
PAGING:
======
Enables or disables query paging.
--------------------------------------------------------------------------------
----------------------------------------------------
SHOW:
====
Displays the details of current cqlsh session such as Cassandra version, host,
or data type assumptions.
Ex:
--
SHOW HOST;
SHOW VERSION;
--------------------------------------------------------------------------------
----------------------------------------------------
SOURCE:
======
Executes a file that contains CQL statements.
Ex:
--
SOURCE '/home/hadoop/CassandraProgs/inputfile';
--------------------------------------------------------------------------------
----------------------------------------------------
TRACING:
=======
Enables or disables request tracing.
********************************************************************************
*****************************************************
KEYSPACE OPERATIONS
********************************************************************************
*****************************************************
CREATE KEYSPACE:
====== ========
Creates a KeySpace in Cassandra.
USE:
===
Connects to a created KeySpace.
Syntax
------
CREATE KEYSPACE <identifier> WITH <properties>
CREATE KEYSPACE "KeySpace Name" WITH replication = {'class': ‘Strategy name‘,
'replication_factor' : ‘No.Of replicas‘};
CREATE KEYSPACE "KeySpace Name" WITH replication = {'class': ‘Strategy name‘,
'replication_factor' : ‘No.Of replicas‘} AND DURABLE_WRITES = ‘Boolean value‘;
USE <identifier>
Ex:
---
USE tutorialspoint;
CREATE KEYSPACE tutorialspoint WITH replication = {'class':'SimpleStrategy',
'replication_factor' : 3};
CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy',
'datacenter1' : 3 } AND DURABLE_WRITES = false;
verification:
------------
DESCRIBE KEYSPACES;
SELECT * FROM system.schema_keyspaces;
--------------------------------------------------------------------------------
----------------------------------------------------
ALTER KEYSPACE:
===== ========
Changes the properties of a KeySpace.
Syntax
------
ALTER KEYSPACE <identifier> WITH <properties>
ALTER KEYSPACE "KeySpace Name" WITH REPLICATION = {'class': ‘Strategy name‘,
'replication_factor' : ‘No.Of replicas‘};
ALTER KEYSPACE "KeySpace Name" WITH REPLICATION = {'class': ‘Strategy name‘,
'replication_factor' : ‘No.Of replicas‘} AND DURABLE_WRITES = ‘Boolean value‘;
Ex:
--
ALTER KEYSPACE tutorialspoint WITH REPLICATION =
{'class':'NetworkTopologyStrategy', 'replication_factor' : 3};
ALTER KEYSPACE test WITH REPLICATION = {'class' : 'NetworkTopologyStrategy',
'datacenter1' : 3} AND DURABLE_WRITES = true;
verification:
------------
SELECT * FROM system.schema_keyspaces;
--------------------------------------------------------------------------------
----------------------------------------------------
DROP KEYSPACE:
==== ========
Removes a KeySpace
Syntax
------
DROP KEYSPACE <identifier>
DROP KEYSPACE "KeySpace name"
Ex:
--
DROP KEYSPACE tutorialspoint;
verification:
------------
DESCRIBE KEYSPACES;
********************************************************************************
*****************************************************
TABLE OPERATIONS
********************************************************************************
*****************************************************
CREATE TABLE:
====== =====
Creates a table in a KeySpace.
Syntax
------
CREATE (TABLE | COLUMNFAMILY) <tablename> ('<column-definition>' , '<column-
definition>') (WITH <option> AND <option>)
Ex:
--
CREATE TABLE emp(
emp_id int PRIMARY KEY,
emp_name text,
emp_city text,
emp_sal varint,
emp_phone varint
);
verification:
------------
DESCRIBE COLUMNFAMILIES;
--------------------------------------------------------------------------------
----------------------------------------------------
ALTER TABLE:
===== =====
Modifies the column properties of a table.
Syntax
------
ALTER (TABLE | COLUMNFAMILY) <tablename> <instruction>
ALTER TABLE table name ADD newcolumn datatype;
ALTER table name DROP column name;
Ex:
--
ALTER TABLE emp ADD emp_email text;
ALTER TABLE emp DROP emp_email;
verification:
------------
DESCRIBE TABLE emp;
--------------------------------------------------------------------------------
----------------------------------------------------
DROP TABLE:
==== =====
Removes a table.
Syntax
------
DROP TABLE <tablename>
Ex:
--
DROP TABLE emp;
verification:
------------
DESCRIBE COLUMNFAMILIES;
--------------------------------------------------------------------------------
----------------------------------------------------
TRUNCATE TABLE
======== =====
Removes all the data from a table.
Syntax
------
TRUNCATE <tablename>
Ex:
--
TRUNCATE student;
verification:
------------
SELECT * FROM student;
--------------------------------------------------------------------------------
----------------------------------------------------
CREATE INDEX:
====== =====
Defines a new index on a single column of a table.
Syntax
------
CREATE INDEX <identifier> ON <tablename>
Ex:
--
CREATE INDEX name ON emp1 (emp_name);
--------------------------------------------------------------------------------
----------------------------------------------------
DROP INDEX:
==== =====
Deletes a named index.
Syntax
------
DROP INDEX <identifier>
Ex:
--
DROP INDEX name;
--------------------------------------------------------------------------------
----------------------------------------------------
BATCH STATEMENTS:
===== ==========
Executes multiple DML statements at once.
Syntax
------
BEGIN BATCH
<insert-stmt>/ <update-stmt>/ <delete-stmt>
APPLY BATCH
Ex:
--
BEGIN BATCH
INSERT INTO emp (emp_id, emp_city, emp_name, emp_phone, emp_sal)
values( 4,'Pune','rajeev',9848022331, 30000);
UPDATE emp SET emp_sal = 50000 WHERE emp_id =3;
DELETE emp_city FROM emp WHERE emp_id = 2;
APPLY BATCH;
verification:
------------
SELECT * FROM emp;
********************************************************************************
*****************************************************
CRUD OPERATIONS
********************************************************************************
*****************************************************
CREATE DATA:
====== ====
Adds columns for a row in a table.
Syntax
------
INSERT INTO <tablename> (<column1 name>, <column2 name>....) VALUES (<value1>,
<value2>....) USING <option>
Ex:
--
INSERT INTO emp (emp_id, emp_name, emp_city, emp_phone, emp_sal) VALUES(1,'ram',
'Hyderabad', 9848022338, 50000);
INSERT INTO emp (emp_id, emp_name, emp_city, emp_phone, emp_sal)
VALUES(2,'robin', 'Hyderabad', 9848022339, 40000);
INSERT INTO emp (emp_id, emp_name, emp_city, emp_phone, emp_sal)
VALUES(3,'rahman', 'Chennai', 9848022330, 45000);
verification:
------------
SELECT * FROM emp;
--------------------------------------------------------------------------------
----------------------------------------------------
UPDATE DATA
====== ====
Updates a column of a row.
Syntax
------
UPDATE <tablename> SET <column name> = <new value> <column name> = <value>....
WHERE <condition>
Ex:
--
UPDATE emp SET emp_city='Delhi',emp_sal=50000 WHERE emp_id=2;
verification:
------------
SELECT * FROM emp;
--------------------------------------------------------------------------------
----------------------------------------------------
READ DATA:
==== ====
This clause reads data from a table.
Syntax
------
SELECT FROM <tablename>
SELECT FROM <table name> WHERE <condition>;
SELECT FROM <table name> WHERE <condition> ORDER BY <column>;
Ex:
--
SELECT * FROM emp;
SELECT emp_name, emp_sal from emp;
SELECT * FROM emp WHERE emp_sal=50000;
SELECT * FROM emp WHERE emp_sal=50000 ORDER BY sal;
--------------------------------------------------------------------------------
----------------------------------------------------
DELETE DATA:
====== ====
Deletes data from a table.
Syntax
------
DELETE FROM <identifier> WHERE <condition>;
Ex:
--
DELETE emp_sal FROM emp WHERE emp_id=3;
DELETE FROM emp WHERE emp_id=3;
verification:
------------
SELECT * FROM emp;
********************************************************************************
*****************************************************
CQL COLLECTION TYPES
********************************************************************************
*****************************************************
List
====
? the order of the elements is to be maintained, and
? a value is to be stored multiple times.
create
------
CREATE TABLE data(name text PRIMARY KEY, email list<text>);
inert
-----
INSERT INTO data(name, email) VALUES ('ramu',
['abc@gmail.com','cba@yahoo.com']);
update
------
UPDATE data SET email = email +['xyz@tutorialspoint.com'] where name = 'ramu';
verifiaction
------------
SELECT * FROM data;
--------------------------------------------------------------------------------
----------------------------------------------------
Set
===
Set is a data type that is used to store a group of elements. The elements of a
set will be returned in a sorted order.
create
------
CREATE TABLE data2 (name text PRIMARY KEY, phone set<varint>);
insert
------
INSERT INTO data2(name, phone)VALUES ('rahman', {9848022338,9848022339});
update
------
UPDATE data2 SET phone = phone + {9848022330} where name='rahman';
verifiaction
------------
SELECT * FROM data2;
--------------------------------------------------------------------------------
----------------------------------------------------
Map
===
Map is a data type that is used to store a key-value pair of elements.
create
------
CREATE TABLE data3 (name text PRIMARY KEY, address map<timestamp, text>);
insert
------
INSERT INTO data3 (name, address) VALUES ('robin', {'home' : 'hyderabad' ,
'office' : 'Delhi' } );
update
------
UPDATE data3 SET address = address+{'office':'mumbai'} WHERE name = 'robin';
verifiaction
------------
SELECT * FROM data3;
********************************************************************************
*****************************************************
CQL User-Defined Data Types
********************************************************************************
*****************************************************
CREATE TYPE:
====== ====
Creates a type in a KeySpace.
Syntax
------
CREATE TYPE <keyspace name > . <data typename> ( variable1, variable2).
Ex:
--
CREATE TYPE card_details (
num int,
pin int,
name text,
cvv int,
phone set<int>
);
verifiaction
------------
DESCRIBE TYPES;
--------------------------------------------------------------------------------
----------------------------------------------------
ALTER TYPE:
===== ====
Modifies the column properties of a type.
Syntax
------
ALTER TYPE typename ADD field_name field_type;
ALTER TYPE typename RENAME existing_name TO new_name;
Ex:
--
ALTER TYPE card_details ADD email text;
ALTER TYPE card_details RENAME email TO mail;
verifiaction
------------
DESCRIBE TYPE card_details;
--------------------------------------------------------------------------------
----------------------------------------------------
DROP TYPE:
==== ====
Removes a type.
Syntax
------
DROP TYPE <typename>
Ex:
--
DROP TYPE card;
verifiaction
------------
DESCRIBE TYPES;
------------
DESCRIBE TYPE card_details;
--------------------------------------------------------------------------------
----------------------------------------------------
DROP TYPE:
==== ====
Removes a type.
Syntax
------
DROP TYPE <typename>
Ex:
--
DROP TYPE card;
verifiaction
------------
DESCRIBE TYPES;

More Related Content

What's hot (20)

SQL WORKSHOP::Lecture 11
SQL WORKSHOP::Lecture 11SQL WORKSHOP::Lecture 11
SQL WORKSHOP::Lecture 11
 
Les09
Les09Les09
Les09
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 
My sql presentation
My sql presentationMy sql presentation
My sql presentation
 
Quick reference for mongo shell commands
Quick reference for mongo shell commandsQuick reference for mongo shell commands
Quick reference for mongo shell commands
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Boost performance with MySQL 5.1 partitions
Boost performance with MySQL 5.1 partitionsBoost performance with MySQL 5.1 partitions
Boost performance with MySQL 5.1 partitions
 
Bibashsql
BibashsqlBibashsql
Bibashsql
 
Oracle training in hyderabad
Oracle training in hyderabadOracle training in hyderabad
Oracle training in hyderabad
 
Les02
Les02Les02
Les02
 
Flashback (Practical Test)
Flashback (Practical Test)Flashback (Practical Test)
Flashback (Practical Test)
 
Connor McDonald 11g for developers
Connor McDonald 11g for developersConnor McDonald 11g for developers
Connor McDonald 11g for developers
 
Chapter08
Chapter08Chapter08
Chapter08
 
Les12
Les12Les12
Les12
 
Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL code
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
 
Les13
Les13Les13
Les13
 

Viewers also liked

PASOS PREVIOS A NUESTRO PROYECTO
PASOS PREVIOS A NUESTRO PROYECTOPASOS PREVIOS A NUESTRO PROYECTO
PASOS PREVIOS A NUESTRO PROYECTOIgnacio Rippa
 
The Best Restaurants in Los Angeles
The Best Restaurants in Los AngelesThe Best Restaurants in Los Angeles
The Best Restaurants in Los Angeles49ThingstoDo
 
Elastic Plastic Foundation
Elastic Plastic FoundationElastic Plastic Foundation
Elastic Plastic FoundationMiguelito Manya
 
SCRUMming “The Photosynthesis of Agile TREES (SCRUM Teams) for Software Deve...
SCRUMming “The Photosynthesis of Agile TREES (SCRUM Teams) for Software Deve...SCRUMming “The Photosynthesis of Agile TREES (SCRUM Teams) for Software Deve...
SCRUMming “The Photosynthesis of Agile TREES (SCRUM Teams) for Software Deve...Sumeet Gupta, CSP, SAFe Agilist (SA)
 
16. Дзяржаўнасць усходніх славян
16. Дзяржаўнасць усходніх славян16. Дзяржаўнасць усходніх славян
16. Дзяржаўнасць усходніх славянAnastasiyaF
 
Хосписная помощь. Комплексный подход
Хосписная помощь. Комплексный подходХосписная помощь. Комплексный подход
Хосписная помощь. Комплексный подходФонд Вера
 
Media and Telecommunications Forum 2016
Media and Telecommunications Forum 2016Media and Telecommunications Forum 2016
Media and Telecommunications Forum 2016Majed Garoub
 
Aapt UX Star Explorer - Presented by Aapt UX Learning
Aapt UX Star Explorer - Presented by Aapt UX LearningAapt UX Star Explorer - Presented by Aapt UX Learning
Aapt UX Star Explorer - Presented by Aapt UX LearningChetana Bhole
 
Prélèvements sociaux sur les revenus du patrimoine Français de Monaco
Prélèvements sociaux sur les revenus du patrimoine Français de MonacoPrélèvements sociaux sur les revenus du patrimoine Français de Monaco
Prélèvements sociaux sur les revenus du patrimoine Français de MonacoThomas Giaccardi
 

Viewers also liked (15)

Presentation1
Presentation1Presentation1
Presentation1
 
PASOS PREVIOS A NUESTRO PROYECTO
PASOS PREVIOS A NUESTRO PROYECTOPASOS PREVIOS A NUESTRO PROYECTO
PASOS PREVIOS A NUESTRO PROYECTO
 
The Best Restaurants in Los Angeles
The Best Restaurants in Los AngelesThe Best Restaurants in Los Angeles
The Best Restaurants in Los Angeles
 
Elastic Plastic Foundation
Elastic Plastic FoundationElastic Plastic Foundation
Elastic Plastic Foundation
 
Resume_Rishiraj Goswami
Resume_Rishiraj GoswamiResume_Rishiraj Goswami
Resume_Rishiraj Goswami
 
SCRUMming “The Photosynthesis of Agile TREES (SCRUM Teams) for Software Deve...
SCRUMming “The Photosynthesis of Agile TREES (SCRUM Teams) for Software Deve...SCRUMming “The Photosynthesis of Agile TREES (SCRUM Teams) for Software Deve...
SCRUMming “The Photosynthesis of Agile TREES (SCRUM Teams) for Software Deve...
 
Preseentacion de administracion
Preseentacion de administracionPreseentacion de administracion
Preseentacion de administracion
 
Garrapatas
GarrapatasGarrapatas
Garrapatas
 
Slideshare
SlideshareSlideshare
Slideshare
 
16. Дзяржаўнасць усходніх славян
16. Дзяржаўнасць усходніх славян16. Дзяржаўнасць усходніх славян
16. Дзяржаўнасць усходніх славян
 
Хосписная помощь. Комплексный подход
Хосписная помощь. Комплексный подходХосписная помощь. Комплексный подход
Хосписная помощь. Комплексный подход
 
Media and Telecommunications Forum 2016
Media and Telecommunications Forum 2016Media and Telecommunications Forum 2016
Media and Telecommunications Forum 2016
 
Aapt UX Star Explorer - Presented by Aapt UX Learning
Aapt UX Star Explorer - Presented by Aapt UX LearningAapt UX Star Explorer - Presented by Aapt UX Learning
Aapt UX Star Explorer - Presented by Aapt UX Learning
 
rumah sehat
rumah sehat rumah sehat
rumah sehat
 
Prélèvements sociaux sur les revenus du patrimoine Français de Monaco
Prélèvements sociaux sur les revenus du patrimoine Français de MonacoPrélèvements sociaux sur les revenus du patrimoine Français de Monaco
Prélèvements sociaux sur les revenus du patrimoine Français de Monaco
 

Similar to Quick reference for cql

Alvedit programs
Alvedit programsAlvedit programs
Alvedit programsmcclintick
 
Oracle 12c: Database Table Rows Archiving testing
Oracle 12c: Database Table Rows Archiving testingOracle 12c: Database Table Rows Archiving testing
Oracle 12c: Database Table Rows Archiving testingMonowar Mukul
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application DevelopmentSaurabh K. Gupta
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스PgDay.Seoul
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humansCraig Kerstiens
 
12c Mini Lesson - ANSI standard TOP-N query syntax
12c Mini Lesson - ANSI standard TOP-N query syntax12c Mini Lesson - ANSI standard TOP-N query syntax
12c Mini Lesson - ANSI standard TOP-N query syntaxConnor McDonald
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所Hiroshi Sekiguchi
 
Oracle12c For Developers
Oracle12c For DevelopersOracle12c For Developers
Oracle12c For DevelopersAlex Nuijten
 

Similar to Quick reference for cql (20)

Quick reference for spark sql
Quick reference for spark sqlQuick reference for spark sql
Quick reference for spark sql
 
Sql2
Sql2Sql2
Sql2
 
Alvedit programs
Alvedit programsAlvedit programs
Alvedit programs
 
Oracle 12c: Database Table Rows Archiving testing
Oracle 12c: Database Table Rows Archiving testingOracle 12c: Database Table Rows Archiving testing
Oracle 12c: Database Table Rows Archiving testing
 
Quick reference for Grafana
Quick reference for GrafanaQuick reference for Grafana
Quick reference for Grafana
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Nls
NlsNls
Nls
 
ZFINDALLZPROGAM
ZFINDALLZPROGAMZFINDALLZPROGAM
ZFINDALLZPROGAM
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
 
Casnewb
CasnewbCasnewb
Casnewb
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
Alv barra her
Alv barra herAlv barra her
Alv barra her
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
 
12c Mini Lesson - ANSI standard TOP-N query syntax
12c Mini Lesson - ANSI standard TOP-N query syntax12c Mini Lesson - ANSI standard TOP-N query syntax
12c Mini Lesson - ANSI standard TOP-N query syntax
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所
 
Oracle12c For Developers
Oracle12c For DevelopersOracle12c For Developers
Oracle12c For Developers
 
Oracle12 for Developers - Oracle OpenWorld Preview AMIS
Oracle12 for Developers - Oracle OpenWorld Preview AMISOracle12 for Developers - Oracle OpenWorld Preview AMIS
Oracle12 for Developers - Oracle OpenWorld Preview AMIS
 
Les01
Les01Les01
Les01
 

Recently uploaded

Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 

Recently uploaded (20)

Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 

Quick reference for cql

  • 1. ******************************************************************************** ***************************************************** CASSANDRA BASICS - SHELL COMMANDS ******************************************************************************** ***************************************************** HELP: ==== Displays help topics for all cqlsh commands. Ex: -- HELP -------------------------------------------------------------------------------- ---------------------------------------------------- CAPTURE: ======= Captures the output of a command and adds it to a file. Ex: -- CAPTURE '/home/hadoop/CassandraProgs/Outputfile'; verification: ------------ CAPTURE '/home/hadoop/CassandraProgs/Outputfile'; select * from emp; CAPTURE OFF; -------------------------------------------------------------------------------- ---------------------------------------------------- CONSISTENCY: =========== Shows the current consistency level, or sets a new consistency level. Ex: -- CONSISTENCY -------------------------------------------------------------------------------- ---------------------------------------------------- COPY: ==== Copies data to and from Cassandra. Ex: -- COPY emp (emp_id, emp_city, emp_name, emp_phone, emp_sal) TO ‘myfile‘; -------------------------------------------------------------------------------- ---------------------------------------------------- DESCRIBE: ========= Describes the current cluster of Cassandra and its objects. Ex: -- DESCRIBE CLUSTER; DESCRIBE KEYSPACES; DESCRIBE TABLES; DESCRIBE TABLE emp; DESCRIBE COLUMNFAMILIES; DESCRIBE TYPES; DESCRIBE TYPE card_details; -------------------------------------------------------------------------------- ---------------------------------------------------- EXPAND: ======
  • 2. Expands the output of a query vertically. Ex -- EXPAND ON EXPAND OFF verificarion: ------------ EXPAND ON select * from emp; EXPAND OFF -------------------------------------------------------------------------------- ---------------------------------------------------- EXIT: ==== Using this command, you can terminate cqlsh. -------------------------------------------------------------------------------- ---------------------------------------------------- PAGING: ====== Enables or disables query paging. -------------------------------------------------------------------------------- ---------------------------------------------------- SHOW: ==== Displays the details of current cqlsh session such as Cassandra version, host, or data type assumptions. Ex: -- SHOW HOST; SHOW VERSION; -------------------------------------------------------------------------------- ---------------------------------------------------- SOURCE: ====== Executes a file that contains CQL statements. Ex: -- SOURCE '/home/hadoop/CassandraProgs/inputfile'; -------------------------------------------------------------------------------- ---------------------------------------------------- TRACING: ======= Enables or disables request tracing. ******************************************************************************** ***************************************************** KEYSPACE OPERATIONS ******************************************************************************** ***************************************************** CREATE KEYSPACE: ====== ======== Creates a KeySpace in Cassandra. USE: === Connects to a created KeySpace. Syntax ------ CREATE KEYSPACE <identifier> WITH <properties>
  • 3. CREATE KEYSPACE "KeySpace Name" WITH replication = {'class': ‘Strategy name‘, 'replication_factor' : ‘No.Of replicas‘}; CREATE KEYSPACE "KeySpace Name" WITH replication = {'class': ‘Strategy name‘, 'replication_factor' : ‘No.Of replicas‘} AND DURABLE_WRITES = ‘Boolean value‘; USE <identifier> Ex: --- USE tutorialspoint; CREATE KEYSPACE tutorialspoint WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3}; CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 3 } AND DURABLE_WRITES = false; verification: ------------ DESCRIBE KEYSPACES; SELECT * FROM system.schema_keyspaces; -------------------------------------------------------------------------------- ---------------------------------------------------- ALTER KEYSPACE: ===== ======== Changes the properties of a KeySpace. Syntax ------ ALTER KEYSPACE <identifier> WITH <properties> ALTER KEYSPACE "KeySpace Name" WITH REPLICATION = {'class': ‘Strategy name‘, 'replication_factor' : ‘No.Of replicas‘}; ALTER KEYSPACE "KeySpace Name" WITH REPLICATION = {'class': ‘Strategy name‘, 'replication_factor' : ‘No.Of replicas‘} AND DURABLE_WRITES = ‘Boolean value‘; Ex: -- ALTER KEYSPACE tutorialspoint WITH REPLICATION = {'class':'NetworkTopologyStrategy', 'replication_factor' : 3}; ALTER KEYSPACE test WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'datacenter1' : 3} AND DURABLE_WRITES = true; verification: ------------ SELECT * FROM system.schema_keyspaces; -------------------------------------------------------------------------------- ---------------------------------------------------- DROP KEYSPACE: ==== ======== Removes a KeySpace Syntax ------ DROP KEYSPACE <identifier> DROP KEYSPACE "KeySpace name" Ex: -- DROP KEYSPACE tutorialspoint; verification: ------------ DESCRIBE KEYSPACES; ******************************************************************************** ***************************************************** TABLE OPERATIONS ********************************************************************************
  • 4. ***************************************************** CREATE TABLE: ====== ===== Creates a table in a KeySpace. Syntax ------ CREATE (TABLE | COLUMNFAMILY) <tablename> ('<column-definition>' , '<column- definition>') (WITH <option> AND <option>) Ex: -- CREATE TABLE emp( emp_id int PRIMARY KEY, emp_name text, emp_city text, emp_sal varint, emp_phone varint ); verification: ------------ DESCRIBE COLUMNFAMILIES; -------------------------------------------------------------------------------- ---------------------------------------------------- ALTER TABLE: ===== ===== Modifies the column properties of a table. Syntax ------ ALTER (TABLE | COLUMNFAMILY) <tablename> <instruction> ALTER TABLE table name ADD newcolumn datatype; ALTER table name DROP column name; Ex: -- ALTER TABLE emp ADD emp_email text; ALTER TABLE emp DROP emp_email; verification: ------------ DESCRIBE TABLE emp; -------------------------------------------------------------------------------- ---------------------------------------------------- DROP TABLE: ==== ===== Removes a table. Syntax ------ DROP TABLE <tablename> Ex: -- DROP TABLE emp; verification: ------------ DESCRIBE COLUMNFAMILIES; -------------------------------------------------------------------------------- ---------------------------------------------------- TRUNCATE TABLE ======== =====
  • 5. Removes all the data from a table. Syntax ------ TRUNCATE <tablename> Ex: -- TRUNCATE student; verification: ------------ SELECT * FROM student; -------------------------------------------------------------------------------- ---------------------------------------------------- CREATE INDEX: ====== ===== Defines a new index on a single column of a table. Syntax ------ CREATE INDEX <identifier> ON <tablename> Ex: -- CREATE INDEX name ON emp1 (emp_name); -------------------------------------------------------------------------------- ---------------------------------------------------- DROP INDEX: ==== ===== Deletes a named index. Syntax ------ DROP INDEX <identifier> Ex: -- DROP INDEX name; -------------------------------------------------------------------------------- ---------------------------------------------------- BATCH STATEMENTS: ===== ========== Executes multiple DML statements at once. Syntax ------ BEGIN BATCH <insert-stmt>/ <update-stmt>/ <delete-stmt> APPLY BATCH Ex: -- BEGIN BATCH INSERT INTO emp (emp_id, emp_city, emp_name, emp_phone, emp_sal) values( 4,'Pune','rajeev',9848022331, 30000); UPDATE emp SET emp_sal = 50000 WHERE emp_id =3; DELETE emp_city FROM emp WHERE emp_id = 2; APPLY BATCH; verification: ------------ SELECT * FROM emp; ********************************************************************************
  • 6. ***************************************************** CRUD OPERATIONS ******************************************************************************** ***************************************************** CREATE DATA: ====== ==== Adds columns for a row in a table. Syntax ------ INSERT INTO <tablename> (<column1 name>, <column2 name>....) VALUES (<value1>, <value2>....) USING <option> Ex: -- INSERT INTO emp (emp_id, emp_name, emp_city, emp_phone, emp_sal) VALUES(1,'ram', 'Hyderabad', 9848022338, 50000); INSERT INTO emp (emp_id, emp_name, emp_city, emp_phone, emp_sal) VALUES(2,'robin', 'Hyderabad', 9848022339, 40000); INSERT INTO emp (emp_id, emp_name, emp_city, emp_phone, emp_sal) VALUES(3,'rahman', 'Chennai', 9848022330, 45000); verification: ------------ SELECT * FROM emp; -------------------------------------------------------------------------------- ---------------------------------------------------- UPDATE DATA ====== ==== Updates a column of a row. Syntax ------ UPDATE <tablename> SET <column name> = <new value> <column name> = <value>.... WHERE <condition> Ex: -- UPDATE emp SET emp_city='Delhi',emp_sal=50000 WHERE emp_id=2; verification: ------------ SELECT * FROM emp; -------------------------------------------------------------------------------- ---------------------------------------------------- READ DATA: ==== ==== This clause reads data from a table. Syntax ------ SELECT FROM <tablename> SELECT FROM <table name> WHERE <condition>; SELECT FROM <table name> WHERE <condition> ORDER BY <column>; Ex: -- SELECT * FROM emp; SELECT emp_name, emp_sal from emp; SELECT * FROM emp WHERE emp_sal=50000; SELECT * FROM emp WHERE emp_sal=50000 ORDER BY sal; -------------------------------------------------------------------------------- ---------------------------------------------------- DELETE DATA:
  • 7. ====== ==== Deletes data from a table. Syntax ------ DELETE FROM <identifier> WHERE <condition>; Ex: -- DELETE emp_sal FROM emp WHERE emp_id=3; DELETE FROM emp WHERE emp_id=3; verification: ------------ SELECT * FROM emp; ******************************************************************************** ***************************************************** CQL COLLECTION TYPES ******************************************************************************** ***************************************************** List ==== ? the order of the elements is to be maintained, and ? a value is to be stored multiple times. create ------ CREATE TABLE data(name text PRIMARY KEY, email list<text>); inert ----- INSERT INTO data(name, email) VALUES ('ramu', ['abc@gmail.com','cba@yahoo.com']); update ------ UPDATE data SET email = email +['xyz@tutorialspoint.com'] where name = 'ramu'; verifiaction ------------ SELECT * FROM data; -------------------------------------------------------------------------------- ---------------------------------------------------- Set === Set is a data type that is used to store a group of elements. The elements of a set will be returned in a sorted order. create ------ CREATE TABLE data2 (name text PRIMARY KEY, phone set<varint>); insert ------ INSERT INTO data2(name, phone)VALUES ('rahman', {9848022338,9848022339}); update ------ UPDATE data2 SET phone = phone + {9848022330} where name='rahman'; verifiaction ------------ SELECT * FROM data2; --------------------------------------------------------------------------------
  • 8. ---------------------------------------------------- Map === Map is a data type that is used to store a key-value pair of elements. create ------ CREATE TABLE data3 (name text PRIMARY KEY, address map<timestamp, text>); insert ------ INSERT INTO data3 (name, address) VALUES ('robin', {'home' : 'hyderabad' , 'office' : 'Delhi' } ); update ------ UPDATE data3 SET address = address+{'office':'mumbai'} WHERE name = 'robin'; verifiaction ------------ SELECT * FROM data3; ******************************************************************************** ***************************************************** CQL User-Defined Data Types ******************************************************************************** ***************************************************** CREATE TYPE: ====== ==== Creates a type in a KeySpace. Syntax ------ CREATE TYPE <keyspace name > . <data typename> ( variable1, variable2). Ex: -- CREATE TYPE card_details ( num int, pin int, name text, cvv int, phone set<int> ); verifiaction ------------ DESCRIBE TYPES; -------------------------------------------------------------------------------- ---------------------------------------------------- ALTER TYPE: ===== ==== Modifies the column properties of a type. Syntax ------ ALTER TYPE typename ADD field_name field_type; ALTER TYPE typename RENAME existing_name TO new_name; Ex: -- ALTER TYPE card_details ADD email text; ALTER TYPE card_details RENAME email TO mail; verifiaction
  • 9. ------------ DESCRIBE TYPE card_details; -------------------------------------------------------------------------------- ---------------------------------------------------- DROP TYPE: ==== ==== Removes a type. Syntax ------ DROP TYPE <typename> Ex: -- DROP TYPE card; verifiaction ------------ DESCRIBE TYPES;
  • 10. ------------ DESCRIBE TYPE card_details; -------------------------------------------------------------------------------- ---------------------------------------------------- DROP TYPE: ==== ==== Removes a type. Syntax ------ DROP TYPE <typename> Ex: -- DROP TYPE card; verifiaction ------------ DESCRIBE TYPES;