0% found this document useful (0 votes)
2 views

SQL Notes

The document provides an overview of SQL, covering Data Definition Language (DDL) for creating and altering databases and tables, Data Manipulation Language (DML) for inserting, updating, and deleting data, and Data Control Language (DCL) for managing permissions. It includes examples of SQL commands such as CREATE, ALTER, DROP, SELECT, and various join operations. Additionally, it discusses advanced SQL features like triggers, views, and aggregate functions.

Uploaded by

Suraj Solanke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL Notes

The document provides an overview of SQL, covering Data Definition Language (DDL) for creating and altering databases and tables, Data Manipulation Language (DML) for inserting, updating, and deleting data, and Data Control Language (DCL) for managing permissions. It includes examples of SQL commands such as CREATE, ALTER, DROP, SELECT, and various join operations. Additionally, it discusses advanced SQL features like triggers, views, and aggregate functions.

Uploaded by

Suraj Solanke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

HA

SQL

i DDL (Dada Qefoitidn longuage)


CREATE DATABasE
CREATE
TABLEoyTabe id it
Name Vanchallo)
Dag Date).
CREATE DNDEX index Nane oN TableName ColumD
ALTER- TA is ued to add medif on delele columa delete

Conhainds rom the aadabae table.


ALTER TABLE myTable DRoP ColuiN col5

ALTER TASLE Col5 int


Mable ADD cal
DAP:- D s weddo delete the table aleng th s data

DROP DATABASE MyDg


DROP DNDEX adose -name
DROp TABLE MYTable

4) TRUNCATE ;- Hs ased to delete the doda prelent inlthe tabe


but this_oill not delete the table

TAUNCAE TABLE mylable;


6_RENA NE - W to genane the able
REApHE ALTER TARLE oTable REVAME To custDnfo;
Commed --line | ’ Single lene Comment
/ t Linel Mut-ina Commert
2 Doto lanipulathon laaguage CoM)

FNSERT TNTO myTabk (coll, ol2, ol)


VALUES (Vali,val2. .. val. );
FNSERT TNTD mylabe VALUES (uva, a,..)
uPDArE - led to modit the eaisthny Valu of ebo
prelet ia the dstable
UPDATE myTahle
SET Col1 = 66,(ol2= 58
wHERE col2 =somethin

DELETE- wded a delete the eecisa oeland prent inthetabt


DELETE FRornyTable
WHERE Candition;

SELET:- Lted to seleot doda tdm DR take


SELECT Col!, Cal 2,.. fRor mylabe
3)Data Condeal lauage (L)

GRANTaivileg N objet To es;


prduilega Cosn be seled, inser,tdek.delete, touDiae, Releesl
a8gea, Cxeate, all. de tan
Stodemet;
SNELIA

CRANT CaMECT ON DATABASE dhDaMe To ueenaDe

GRANT Mae an schema


GeRANT USAGE 0N SCHErdA dh-oame To LeeDame
#&RANT Acees to all'tables io the o8
cRANT ALL pRTUTLEaES ON ALL TABLES N
SCHEMA 5chem4-nn
To Wencme
cRANT ALL PROVDLERES ON ALL SEQUENCES LN
ScHÆr1A
Schemaname To wtcnabe
GRANT AL PRIVALECBs ON
DATABAsEdbname To_ korane
dele

GRANT Permission to caeatt D8:


ALTER Wenane CREATAD8

1
ALTSR SGR OyJer TH SUPERUS ER

REVORE pivilege ON objet FRor wer


e2. REVOK E D&ETE, DFDATE 0N ORDERs Rort ut:

CoMMTT ’ Wed to sae all changey mode to the D8 in


the luaent dhanlathien.
RoLl8Ac; ueol to geest the changel made to D8
in the Cusent danlaahon
RetSAVGPOTT ’ tled to detine aidenter hich Pout tobe
cuned tacnsachon sveport.
USAvEPofNT Sovefoint ane;
RoLLB Ack To sovePo'ntnane ;
Saveptname: T0delete
RELEASE SAVEPaTNT Soeld
KI

ioseadcd in the table. Ps im ale io ehslain cugas


oiodepit) the dta inseoted to a tasle
not
NoT NULL !- The Columo
The col umo Mut
Mujt have
have NvL
NVLL Valle whik he
indo dhe tdble
UNTO DE- 7he colemn mwt have ditf valy fe sl!
MOs prelerto the tablo
PRTtPRy KEy- T is a olumn ahich is Weol to uniqucly
identify table Dhich efenerrel
Pimay e io other dable
6 CHsk checke foa sneic ondition ahile taseatindatu into
the dable

valu, is Gat menthaned hle caeatin a dable,then


the deflt yalue is ioSeted Dhile ioseshyg lece.

Mothitally when a speite euent ocllns e


Syhtoxr
CREATE TRD&EER doAec
doggesDADe laefa RE/A£TEA] [DASetlypdaele
ON
TabloDme

e-f. c REArE TAIG &ER oRo HFS AerER TNSERT ON OR0ERS


TNScRT DNTOORDGRHIStORy
VALVAS (ned. ORDERED, De)-TEr, ce3 B|LAL. Nou
Tn this, we w)) see ORONSRHTSTORY teble autamktaly ge
dsders teeble.

DROP TRI EGER gger-pane Doop er


AZ IA X
uith seleat a a
Statemet oheae fues there is a need ta 4 te

gehieve data feam_puhple table LdL5 30


Table L Table 2
TNNER TOIN
D ambine) the valu) foa bodth A
tabebaled oo madchi Coteria
SY- SELECT t CROM TALE TVNER TOTN d 5
ABLE2 WhERE TABLE1. A=TAA LE2.A;
LGeLTOTN' A A
Retinall the vellle! from the left dable do
of te cond°&etinn onl the Matchi 20 del
Vol1u fom the 2nd table
The enmatched sad Valus of aht hand
table oilL be epreleaded ol oull
RIGHT TOLN
Retrn dll the valel from the ht hoand A x
dable of the Cand sathinl any themothiyj
Values fom dhe ef hand abe. The
nmatched gos Valuea ofhe leff hand NulNue
table Di be aepreleated al Nu

Caoss joio medchel each aa) of the fasst


a
tabie with euej a
Syx'- 5elect A,a,} from Tab le ) CRoss Toro Table 2; 80
b
Rethnt all de neo do foom dhe bodh tabler, A a_AX
Cyen jf dhene is ndt a mdch.tor roDs Qth | aa o
Q match he va luas froo both tables dae b4 ul Na
available, f there is net a mch the emP d5 d30
field! tdill get the Valuo yull. Nll Nulle

Roas coHh no madch ail Aet a NULL Valle felds


fom the opPasie tabie.

ed to Conbne the aeyu-set of tod or MoneUen


UNTON Selecds only dishinct Valuug..
The querse) in the nioo mut follod -
0 They Myt bave same n0. of calLuos.
The col on out hoe the sare
The olund ms)B be io the
Syntaa. select quel oN seledt qea 2
* UNTONA ALL t retund dupkcade valaes if the sone tous
in the tüo quesiel csetnaj the eoatt
setaj the estatt sae elli

Coud O, Mon), NL)SOtt), Ave to AoL the ent

AHouing The having claute wal added to sg becausd the


WHERE claule anngt be uled th agr rp
Agpcgak funthions
ha-addin! HA VDNE e_cuo bate copdlle ue do
WHERE Clouyes.
tEXTTs The edlsts opexador is ied to tet tor the
esistance of an ne oad in asub quen
The eousts oper cbr menn TRUE E the
subguefe
select Coji
Colt foro Table
WHERE EXDSIS_ (selec ol foro Table2
WHERE ond")
NOT ExNSTS- TO cheCk ahich uta meas that do notLbave
ordexs We caA the No cpencdor togehes th he

tANY - TheANY opeados alaasau


alloas Hau to pestor a CiepaisOn delet

be a Single alumo value o_a aange ot othe vede)


Detnnl TRUE ANy of the sob quert rmett the ard
ANY neans tbat tte
for a of the valuey in the aange
seleltcol fraró table) ohere (o/l'e ANY (seleg co for
Table 2Dhere cor
AL- ALL Means thot the aod oill be tle Ony t the
OReaatioA is tue fer cll les in the rant
Tt aetuan! o boolean Valle a a reet. vaty
T4 metnJ Toue if ALL af the sub que mes he Cand
ct wed_coith seleet, Dhece hovn taterents.

tSELET DRITNT !- it is uiedto metao ony distint Valuet

SFLET CoUNTD2STRNt) Retan the Count of dhadahq


Select CDat (oishnt alupo) fom Tabe:

descercing onder.
AsC. TO sot the eod io lcerdiy
Bo defaut, its setuny
wOdes we DESC o .
the
t L T T T Sused t o _ i t

the eCosds to retun,

1LTT 20 O£fSET 40
e

NOTE
it mean_stontig aeond
ONDRetunmalejt Vallue.

tcAX)Retuan dong felt value.

the ne Df oows that matehe< a critelie


t COUNTO - Retuan
NulValue ase nat eonted

the oVerage valu_0f a nupeic olumn


tAVG ) '-Rethn
Null i9noxe)
NuDERTC. ) ’ ujeoesato to Ound the ag PaZL

SelectAVe (Price)! NUMERIO CIO,)


ioa WHERE Clauic o
K 1IRE - The LIRECPesotorr is Lled
Seanch for aSfied Pattesn io a colunn.
Thexe Oce toacö|ld ard! oflen uled in Coautiaa

lndersoae sgo arelerds Onesstale chatR

b t eah! erert
snd ont one chosa te.
LLKE Oesder s CASE eite.
EHAI kIe

iosenlite seanb, We
the DkE oPesator instead

clae.
4's a shot hand for uhpe oR Coro
e whexe Cauntg
NoT
teu oetan all gecond l thot ase not an all
in the st

|t TNSELEA) - We can Wle a sLsT statemest inltcle the


paneathess to aehLao all aeriadi that an n the
Helut of the seect stdenent
t BETWEEN - Gelects waluel cdhio sanAe The Wallleg Can be
Oumbes, teot or datel.
Sbere price Bethseen o AND J6
Qhexe PsoductNane Between Poylovc' AND Toe
Qhexe ondesdate Aetleen l2024 -a2-27 AND '2024 -Q3-26;

FCASE - The CAsE op eogoel thaough Cood letn a


Ablue Ohen the fost Cordihon met onte a aos ue
s md
ane
the vale ia dhe elSE olaute.
faue, id aet
ElsE

etua
e SELET praduetDarne
CASE
WHEN pale xD TiEN
WHEN THEN
Poice 50 THEN HIgh poco Paduct
ELSE
ebpd oomal Prads'
END "'Prite Cautejar"
fRort Peodues j
Vie) is_q ques clhich iss Stosed in the
io D2 h
De
3eseladex Vieds dxe but a pseudo tabie
Viens can be contao a cempez queg Dhich aehieve det
fom mlthple tablel.
So inltead of aiti a enped guey euesgime,e.
Can Caeate a'VSene eCall t When evex

Cxeade Vie)
fseet
ir CREATE VTEW Vieil-name As
Call vi) '-seleet 7 om vil-Dam
ALTER VDEW uiredoame As (seect que
Delete v'lD DRp Viednamc

You might also like