SlideShare uma empresa Scribd logo
1 de 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;

Mais conteúdo relacionado

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Último (20)

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

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;