Dbms Notes
Dbms Notes
Key
accele
Cll rows
disp
select Promempiayee
drop
drop
si use to delete table fruncate
3yntax table tablename
eqdraptableemploy ee
heck sihng seleca adrom employee
Ls ulget emsr mugitablen or uied does nat extal
aTruncateF:Tis tned to delete all the data a
the tablebet the table billexistthe tab le
oll be em pty Gtab)e stracure. lem ain, datn will go)
3ytaxtruncotetabledable nam
dhancadetable emploube
Rendme Rename theltehle
on the Cols
alter: T TA Ched t pes om op
add ne couimn to the
i) add/: It is tNed to
existing tablY)
alter tabl e tablename
add col_namedato_type C3ze)
(which tab le to alter)
eg alter table em plo yee (ohich col to add tee)
Qdd age numbesle)
thec cols u haue
descrbe employ ec:tellsdll
Ltable ka shuctuse display karta ho
eCkaunsa o, daa type preaslon,Ien
desc e mplcye
Tt s uyed to delet cols no ns
alter tabletablename
Syntax drop cotumn columo-nme
Clter tabletablengme
e enaztoe Column. jd toe_id
2) DML Commands
a insertu Tmert rod/reco rd tuple a table
8yntax mert roto ta6le _namelcoli cal2,-cl
valu es Cvou Nal
updatet
the condition
ie tubed b update data that stis lies
I2 we dont orite con dutic then (a the soss
tdill be updated
syntax, updotetablename
Set col1= Vai Cola = val,
update empleyee
set
salang
uhere salay<= 3000 con diiov
alowe)
Teuoke Createtable
tom Santosh
TCL
a) Cam mif : lo Sawe chane
g 6 ) DML camm cande)
+) Rsllba d lo cancel the changes made by DL comncad
Synax select *
rom erap table_name auhere conai
Hott, o2,,otN seleted
enpreIOn
3el ect
*lcolicolN/expTemign
romtable-name
ohese conduticy
Guidelines
D Not case gensitive
gelecSELEC
3ELEC E
2)You cannot obbseulte COmmands exceptdescibe! desc
+ j
command
bettes t tâate each clae Line
Lotuniil sep
To com pcthe stsing date de neod t
wwrite in quotes 6 3
206
)DísploySelet
those* empleyees wh ose salay 3000
rom employee Display al colr
ohere galary>3000 or the Cond
where dep-MkT
9horkiqiin
gelt*
mkt dept and galany > 3000
rom emplegee. andl
where dept MKI Sala ry > 3000
whose name startsith (Pla cemevt)
select*
rom
emplogee. baki aage anything
uhere name ke
Ts not aitoÛ ed ed or patten -
matchin
ohere ng me like 9/ or name Iike s . 9
Noo? undescores
>eprejenb no of chara
ctes.g csste
Date
only ah ead
letteh no- o letters.
uhere nome a hends oith h
emplege houing
where name
6
a
fike
in name
ay.
% = 0 ya 0se
JYad d charactex
Kahtpe to name: me cata ha.
s)alag ts betoeen
where name
Iike a cd
ame Comtainina a,cd
matched
petfen b be
whese
8elect *
atog b/ 2000 56oÜ
11
2rom epleyee
2stCAIA
here Salary >= 2000 and
ery< =5000.
Dele
Prom empleyee
whereSalary 2000or solary= 3000 or galary
to auoid multi ple orop
ohere salary Îh C2000, 3000, 4000)
whene
where salary
salarynot in (2000, 30o0
to 4000
ekdud e them
Displsy cnnual salary ag emplogees
select ld,name Saldy * 12 as
rono empleyee Annual shlarg
Put it in doubte quoty
qu
name Fist Na me o Tnctude space
alaing
2or display purpese, the table cos
narne· remaiwm the 2ame
aroup bg or qraupi ng
Suppese we hawe3 Cunique) deptsanel
HKT, HR,Admin and ant to display
gaag or minimun.
each deptks
8clect dept, min (salary
troro
employee
gYoup hy dept
It wilt
will gvoup the vos and disploy
peh group
order bya ltbays comes ost Tn SQL
hoting It diaplay
the conditja
Those groups that satia ie
on aggreqote unctioshere clause is nGE
allowed hawing clausesg
Dig? b/0 ohee > hawing 2
sk where clauu e is esed to restáic ro hauing.
cluise s used fo testit re ps
add
e s e lselet
e dept), sum (salary) ottdeach
solarias
dept
rom employee
replaces here heuinq saldry o00 ke
cond MKT I25 Coo
Presemt in
gTOup by depti HR 6o00o
the group by cauuE
Diaploy e emp
nox e emp
no in edch dep! (each >qrep
>
MkI 3
select dept , colunt(Hepidl HR
Rrom employee ADMIN
by dept
e
order by coun(id)
Any ard ADMLN
MKt3
hauíng
group byS
order HR 3
orderb
In short
select
rom onty 6causey fn sgL
here
gveup by ordeh oesíortg
clauses
6
habing
order by
Select
Brom emplogee (
uhere saly any Cselect SaloE
Can begreter than 2rom em ployee
either /ang ct the where dept(MKT)
ang (2 000, 3000, S000)
Procos Cmeaning
Jngormation prsesed , otganI~ed datu)
4on delete casCad e
t o del ete nuL
elacae
Dete
Pags
(onstraints
Forelgn key t
Pk.rejeks Pk o2 othe table.
fore'gn ker Ceust id) regerences ustamer (Td)
a d he colin the table other table is pk
Cna me)
Oniaue:
Cieatetable tustemer(bhan
foatca
Ngme VARCH AR (255) ONIQUE
A) check
Create able acount
Falan ce int C1o)
CorvSTRAINTaccbalance _chk CHEck
balan ce > lo00J
Deault
Create table accrcunt
20uejoin
OR
Kight j'oin
Data
key LILo Ru Ra
Merged
Remaining
botd Null Nt
4
vatuesstbsirute
table
key RI R2
2 Meqed dat e
3 Romauning
Dda ot he
Right tabie
elacGatA
Data
Page
teble able
L2 key Ro
1
2
3 3
key k,
2
FULL JomN Leydot
3
not waulable
NUL L
7
Nut
EalljojnLet join URigat sin
Syntdx
LT R
A - R2
’2 B
SReltant
RI
A 3
A 4
B 3
B
cols ke
Join appljcable on coll mngCmaBching
Un'on pplicable on al sows just gnoing Yepea
valies
LE4 jion
eelect
Prom project as p
le2t join employee
9 onpd edd pempld
T T2
Set op
matehtn coal combines salect stm
Cotumn- Wise c¡mbn row- ise comb n
Dote types can be digfa Data typ o as can be sare
there can be repetitive No cep Yos / cols
Tos cos
Noo cos moy not be No o cols has to be Same
Same
’ hornizontal Comb1. VeHcal comb^ o reults
B ThtersectTD T
Select rorg T Select DISTINCT id 2rom T
INTER9 ECT X. INNER JoIN T2
Select *ram Ta
A
2 A 2 8
9MINUsT l
A
2
3
select d FROM TL
LEFT JotN T2 LaingCid )
A A
8
3
4
Data
Al employees he comp
selec Jrorm Det 1
UNION
gelect * rom Dept 2
) a emp in all depts ho esk as 9ales mon
Select* rom debt
dept whererole sr 9 les ma 1
UNtON
select * rom denta ohere ole Sales man 29
both
3) emp workine in att depts
DZaat sel et rom dep depfi geg
INNER JoIN dept
sTng E-d emprd ) al cots o dept