Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

SNONFLAKEE

BEGINNER - NOTES
SeL can be devided into five different langua-e
Command types. T0 ereate Snouwflake objects, you
ned to usÁ Data Defni lion kanßuae (DDL)
COmmands, Geenß acess to thöse ohjecks TequeS
veyiies
the Data control°Languaße (DCL), Next you'll
use Data Manipulation kanguaße CDMI) COmmands
to manipulate the data inta and out of Siou flake.
Transackion Control tanguape (rcA) comimands
enable you to manag transacton blodks. Data.
query lnguae (bQL) Statements are then used
to acially Quer tthe data..Follouing is alist of
Common 'soL conmmands, orfanise by type*
DDL (Data Definition Language) Commands:
CREATE-To CTeate databages, tables, trioßers and
other data base objeets
" ALTER-TD chanße or modify the exisin
Stuctareof the dafabase, t also chanßs
Qmeet-Kant the Scheme of he database objerts.
"TRUNCATe -TO delete or remove all the eords
fsom the table. Also Yemoves the
Space atlocated for storing the table
reords.
RENAME- TO changße the name of the daBa base
table.

" DROP - To delete /rermove the daBabase objects


from the sQL dakabase. We Can easilg
Temove the entie table, view,or index.
from the databage using ths.
DeSsCRIBE SHOW USe
SeT UNSET " COMMeNT
DCL(Daa control kanguaße)comTmands:
"GRANT-Tt fives uses access privilees to the
database.
"REVOke -This Withdraucs the users acess priviles
by frven by using the Grant.
DML (Dta ManipulalÕn kanguaße) Command3
" FNSERT- Used to (nsert the daa into a table.
"UPDATE - to update enistinß dan within a table.
DeLETe -TD delete TeCords from a data base table
" L0ck- Table control concurencH
" MERGe CopY INTO PUT
G ET AIST ReMOVe
VALIDATE
TCL (Transaction Control. Lanßuaße command
"INSERT
BectN - 0Pens a Transactton
"CommiT- coTnmits a Transactín
ROLL BACK- Roll backs a transaction in case of
any ersors OCums.
D9L (Data Query lanpuage command
" SekecT- used to Yetrieve data from the
data base.

-Www. bepec.in
this oding:
Use ROLE SYSADMIN;
UsE WAReHOUSE COMPUTE_- WH;
CRCATE OR RePLACe DATA BASe DeMO4_DB;
CREATe OR REPLACe SCHEMA SUBQUERI ES;
CReATeOR REPLACe TABLE DEMO De. SUBqUE RIeS
(TD Inteßer, ANTT Snteßer, TOtal Integer
INSE RT INTO DERIVeD (TD, AMT, Total)
VALDES (, 1000, 4000),(, QO00, 3500),(3, 3000,
(5, 5000, 3400, 6, 6000, Qaaa);
SELECT *+ FROM DEMO4 DB.SUBUERIes. bERIVeD;
SeCeCT
TyThs C0ding :
CREATE OR RePLACe TABLE DEOA DB. SUBQUeRIeS
(D Tnteger, AMT Tnteger, Total Tnteger
INSERT TNTO TABLe R (TD , AMT ,TOtal)
VACUES (1, 1000,8300), (e, 1001, 190), (, 3000,
5, 1200 , 3232), 6, (000, 222);
SeLeCT * FROM DEMD4_DB. SUB QUeeiES.TABLE2
We can write an uncorelaled Subaaery :
ty ths Coding
SELECT TD, AMT
FRONM DEMO4 DB. SUBAUe RIes. DERIVED
WHeRe AMT = (SeLECT MAx (AMT)
FRD DEMO4_DB.SUBveRieS. TABLE Rj
Aets Try executinß a coelaled Subiery now;
SeLECT TD, AMT
FRO DEMO4_ DB. SUBQuERIes. DERIVeD
WHeRE AMT =(SELECT AMT
FROM DEMD. D8.SUB QUeRIes,TABLeR
WHERe TD = TD);
Let's o head and add MAK:
SeLECT ID, AMT
FRON DeMD_DB.SUBQveRIEs. DeRIVeD
WHERe AMT = (SeLecT MAXx (AMT)
FROM DEMD4-DB. SUBAUE RIES.TABLE.R
WHERe ID = TD);
-wlww.bepec. in
Lets see wha! happen IE We change the
eyuals ipn to a greater- than thing:
SELECT TD, AMT
FROM DENO4- DB. SUBAVERIes. DeRIVED
WHERe AMT > (SELeCT MAX (AMT)
FROM DEMD4_DB. SUBQUe RIes.TABLER
WHERe TD = ID);
kets &ee what happeng if we change MAx
to AvG3
SELECT TD, AMT
FRDM DeM04_ DB.SUBQUeRIES. DERNeD
tWHERe AMT> (SeLecT AVG (AMT)
FROM DeMO4-DB SUBQUERIES.TABLER
WHERE TD = TDD;
Try this codng :
SeLECT TD, AMT, AMT * |D as AMT1,AMT1 t20
FROM DEMD_ DB. SUBQUeRIEs. DERIvED;

-Waw. bepeto io
Ty this coding :
SeLecT Sub.TD,Sub.AMT, Sub, AMT1+ R0as AMT
FROM (SeLECT TD, AMT, AMT 10 Qs AMT1
FROM DEMD4- DB. SUBAveRIES. DERIVED AS SUb

Ty This (oding -
WiTH CTer AS (SELeCT TD. AMT, AMT* |D QS AT
FROM DEM04_DB.SUBQVeRIes. DERIVED)
SELeCT a.DD, b. AMTb-AMTR+ 20 as
AMTR
FRON DeMO4- DB. SUBQveRIes. DeRIVED a
ToIN CTeT b ON (a.ID= b.TD);

-wwtw. bepec. in @meet Kanth

You might also like