You are on page 1of 6

SQLWORKSHEET

1a)MissNi
shacr
eat
edatableJOURNEYwith3rowsand5columns.Sheaddedonemore
rowtoi
tanddel
eted1column.Whati
sitcar
dinal
i
tyandDegr
eeofthetabl
eJOURNEY?
1

b)Expl
ainr
efer
ent
ial
int
egr
it
ywi
thr
efer
encet
oDBMS. 1

c)Consi
dert
het
abl
eSTUDENTandSQLst
atement
s 2

Admno Rol
l
No Cl
ass St
udentname Fat
her
s
Name

4001 1 XI
I Ram Raj

4002 1 XI Rav
i Rao

4003 2 XI Rakesh Ramana

4004 2 XI
I Raj
i
ni Raghav

I
dent
if
yCandi
dat
ekeyandPr
imar
yKeyf
ort
heabov
etabl
e.

d)Consi
dert
hefol
l
owi
ngt
abl
eEmpl
oy,
Wri
teSQLCommandsf
ori
toi
vandout
putf
orvand
vi 6

No Name Age Depar


tment Dat
eof
Joi
n Sal
ary gend
er

1 Jugal 33 Comput
er 10/
01/
97 12000 M

2 Shar
mil
a 31 Hi
stor
y 23/
03/
98 20000 F

3 Sandeep 32 Mat
hs 12/
12/
96 20000 M

4 Sangeet
a 35 Hi
stor
y 01/
07/
99 40000 F

5 Rakesh 42 Mat
hs 05/
09/
97 25000 M

6 Shy
am 50 Hi
stor
y 27/
06/
98 30000 M

7 Shi
vOm 44 Comput
er 25/
02/
97 21000 M

8 Shal
aka 33 Mat
hs 31/
07/
97 20000 F

i
)Di
spl
aydet
ail
sofal
lfemal
ehi
stor
yteacher
s

i
i
)Countt
henumberoft
eacher
swhosenamehav
e“h”assecondl
ett
er

i
i
i)Di
spl
ayName,
age,
Sal
aryi
nthedescendi
ngor
derofageandascendi
ngor
derofsal
ary

i
v)I
ncr
easet
hesal
aryofal
lComput
ert
eacher
sabov
e40y
ear
sbyRs1000

v
)Sel
ectName,
Depar
tmentf
rom Empl
oywher
eyear
(Dat
eof
Joi
n)i
n{96,
98}andgender
=’F’
;

v
i)Sel
ectDepar
tment
,Sum(
Sal
ary
)fr
om Empl
oyGr
oupbyDepar
tmenthav
ing
Page1/
1
count
(Depar
tment
)<3;

2.a)Wr
it
eSQLt
oCr
eat
ethef
oll
owi
ngt
abl
eBANKwi
thspeci
fi
edconst
rai
nts 2

Col
umnName Dat
aty
pe Const
rai
nt

BankCode Char
act
erof10si
ze Pr
imar
yKey

Br
anch Char
act
erof30si
ze

Ci
ty Char
act
erof30si
ze

Budget Numer
ic(
7,2)

b)Canwechangethecolumnnameusi ngAl
tert
abl
ecommand?Changet
hedat
aty
peof
Budgetcol
umnofabovement
ionedBANKTabl
etoNumer
ic(
12,
2). 2

d)Consi
dert
het
abl
esHANDSETANDCUSTOMER

HandSet

Set
Code Set
Name TouchScr
een PhoneCost

N1 Tal
k2G N 5000

N2 Tal
k3G Y 8000

B1 SamWaad N 14000

Cust
omer

Cust
No Set
No Cust
Addr
ess

1 N2 Del
hi

2 B1 Mumbai

3 N2 Mumbai

4 N1 Kol
kat
a

5 B1 Del
hi

i
) Di
splaytheCust
No,Custaddressandcorr
espondi
ngSet name 2
i
i
) Di
splaythecust
omerdetail
sforeachcustomerwhousesaTal khandset 2
i
i
i) CountthenumberofcustomersinMumbai whopurchasedTouchscr
eenset 2

3.a)Whi
chMy
Sql
commandi
susedt
omakeper
manentchangesont
hedat
abases. 1

b)Whent
ouse“
AS”oper
atori
nMy
Sql
stat
ement
s,gi
veanexampl
e 1

c)Whati
sthedi
ff
erencebet
weent
heAl
terandUpdat
eCommand? 2

d)Canat
abl
ehav
emul
ti
pleFor
eignkey
s. 1
Page2/
2
e)Di
ff
erent
iat
eHAVI
NGandWHEREcl
ausewi
thanexampl
e. 2

f
)Di
ff
erent
iat
ebet
weenDDLandDMLcommandsi
nMy
SQL. 2

g)Expl
aint
hewor
kingofLI
KEcl
ausei
nMy
SQLwi
tht
hehel
pofoneexampl
e. 1

h)Di
ff
erent
iat
ebet
weenCOUNT(
)ANDCOUNT(
*)f
unct
ionsi
nMy
SQL. 1

5.Considerthefoll
owingt
ablename“ EXAM”wi t
hdet
ail
sofmar
ks.Wr
it
ecommandof
MySQLf or(i)t
o( i
v)andoutputfor(v)to(v
ii)
.
7
Table:EXAM
Adno SName Percentage Cl sect
ion Stream

R001 Sushant 90.


2 12A Sci
ence

R002 Vai
dyanat
h 80.
5 12B Humani
ti
e
s

R003 Mi
ara 68.
9 12B Sci
ence

R004 Ni
ara 96.
0 12A Commer
c
e

R005 Shi
nji
ni 88.
9 12D Commer
c
e

(
i) Todi splayalli
nformati
onoft hestudent
sofhumaniti
esindescendingorderof
percent age.
(
ii
) Todi splayAdno, Name, Per
centageandStream oft
hosestudent
swhosenamei s
l
esst han6char acterslong.
(
ii
i) Toaddanot hercolumnBus_ Feeswi t
hdataty
peandsizeasDecimal (
8,2).
(
iv) Toincr easepercentageby2%ofal l
theHumaniti
esstudent
s.
(
v) SELECTCOUNT( *)FROM Exam;
(
vi) SELECTSName, PercentageFROM EXAM WHERENameLI KE‘N%’;
(
vii
) SELECTROUND( Percentage,
0)FROM EXAM WHEREAdno=‘ R005’
;

6.Consi
dert
heTableSHOPPEgi
venbel
ow.Wr
it
ecommandi
nMy Sql
for(
i)t
o(iv)andout
put
for
(v)t
o(vi
i)
.
TableSHOPPEE:
Code I
tem Company Qty Cit
y Pri
ce

102 Bi
scui
t Hi
de&Seek 100 Del
hi 10.
00

103 Jam Ki
ssan 110 Ki
l
kat
a 25.
00

101 Cof
fee Nest
le 200 Kol
kat
a 55.
00

106 Sauce Maggi 56 Mumbai 55.


00

107 Cake Br
it
anni
a 72 Del
hi 10.
00
Page3/
3
104 Maggi Nest
le 150 Mumbai 10.
00

105 Chocol
ate Cadbur
y 170 Del
hi 25.
00

i
)Todi
spl
aynamesoft
hei
temswhosenamest
art
swi
th‘
C’i
nascendi
ngor
derofPr
ice.
1

i
i
)Todi
spl
ayCode,
I
tem nameandCi
tyoft
hepr
oduct
swhosequant
it
yisl
esst
han100.
1

i
i
i)Tocountdi
sti
nctCompanyf
rom t
het
abl
e. 1

i
v)Toi
nser
tanewr
owi
nthet
abl
eShoppe 1

110,
‘Pi
zza’
,‘
PapaJones’
,120,
‘Kol
kat
a’,
50.
0

v
)SELECTI
tem f
rom Shoppewher
eIt
em I
N(‘
Jam’
,‘
Cof
fee’
); 1

v
i)SELECTCount
(Di
sti
nctCi
ty)f
rom Shoppe; 1

v
ii
)SELECTMI
N(Qt
y)f
rom Shoppewher
eCi
ty=‘
Mumbai

; 1

v
ii
i)Todi
spl
aydi
ff
erentci
ti
es. 1

7.1)Whati
sMy
SQL? 1

2)IsNULLv aluethesameas0( zero)?Wr i


tethereasonf oryouranswer .
1
3)Wr itetheUPDATEcommandt oi ncreasethecommi ssion(columnname: COMM by500
ofal l
theSal esmanwhohav eachiev edSales( Col
umnname: SALES)mor ethan200000.The
table’
snamei sCOMPANY.1
4)Whi leusingSQLpat ter
nmat ching,whatist hedi
ffer
encebet ween‘_’(under
score)and‘
%’
wildcardsymbol s? 2
5)Howi sPrimarykeyconstrai
ntdi f
ferentfr
om Uniquekeyconst raint
?
2
6)Wr iteonesi mil
ari
tyandonedifferencebet weenCHARandVARCHARdat aty
pes.
2
7)At ableFUNFOODhas13r owsand17col umn.Whati sthecardinal
ityanddegreeofthi
s
table?1

8.a)ShanyaKhannaisusi
ngatabl
eEmploy
ee.I
thast
hef
oll
owi
ngcol
umns.
2
Admno, Name,Agg,St
ream
[
columnAggcont ai
nsAggregat
emarks]

Shewantstodisplayhi
ghestAggobt ainedineachSt
ream.
Shewrotethefol
lowingstatement:
SELECTStream,MAX( Agg)FROM Empl oy
ee;
Butshedidnotgetthedesiredresul
t.Rewrit
etheabovequer
ywi
thnecessar
ychangest
o
hel
phergetthedesiredoutput.

Page4/
4
b)HowmanyPr
imar
ykey
(s)canbedecl
aredi
nat
abl
e?
1

c)Mr
.Janaki
susi
ngatablewit
hthef
oll
owi
ngcol
umns:
2
Name,Cl
ass,
Cour
se_
Id,Cour
se_name

Heneedstodisplaynamesofstudents,
whohav enotbeenassignedanyst ream orhav
e
beenassi
gnedCour se_
namethatendswi th“economics”
.
Hewrotethefol
lowingcommand, whi
chdi dnotgivethedesir
edr esul
t.
SELECTName, ClassFROM St
udents
WHERECour se_name=NULLORCour se_name=” %economics”;
HelpMr.Janaktorunthequer
ybyr emovingtheerrorandwritethecorrectquerr
y.

d)Therei
sacolumnSalaryinaTabl
eEMPLOYEE.Thef
oll
owi
ngt
wost
atement
sar
egi
vi
ng
di
ffer
entout
put
s.Whatmaybet hepossi
bler
eason?
2
SELECTCOUNT( *)FROM EMPLOYEE;
SELECTCOUNT( SALARY)FROM EMPLOYEE;

e)Mrs.Kumari susingtableSTUDENTSwi t
hthef ol
l
owingcolumns:
2
RNO, ADMNO, NAME, AGGREGATE
Shewant stodispl
ayallinfor
mat i
onofstudentsindescendi
ngorderofnameandwithi
n
ascendingorderofaggregate.Shewrotethefoll
owingSQLqueryandshedidnotgetthe
desir
edout put
:
SELECT*FROM STUDENTS
ORDERBYNAME, AGGREGATEDESC;
Rewritetheabovequeryt ogetthedesi
redoutput.

9.Q.6.a)Wr
it
eMySqlcommandtocreat
etheTableVEHI
CLEi
ncl
udi
ngt
heConst
rai
nts.
2
Tabl
eVEHICLE:
Nameof Type Si
ze Const
rai
nt
Col
umn

RegNo Char 10 Pr
imar
yKey

RegDat
e Dat
e

Owner Var
char 30

Addr
ess Var
char 40

b)InaDatabaseBANKtherear
etwot
abl
eswit
hsampl
edat
agi
venbel
ow:
TableEMPLOYEE:
ENO ENAME SALARY ZONE AGE GRADE DEPT

1 Mona 70000 East 40 A 10

Page5/
5
2 Mukt
ar 71000 West 45 B 20

3 Nal
i
ni 60000 East 26 A 10

4 Sanaj 65000 Sout


h 36 A 20

5 Sur
ya 58000 Nor
th 30 B 30

Tabl
eDEPARTMENT:
DEPT DNAME HOD

10 Comput
e 1
rs

20 Economi 2
cs

30 Engl
i
sh 5

WriteMySqlquer i
esf
orthefoll
owing:
i
) Todi spl
ayENO,ENAME, SALARYandcor r
espondi ngDNAMEofal lt
heemployees
whoseagei sbetween25and35( bothv al
uesi nclusi
v e)
. 2
i
i) Todi spl
ayDNAMEandcor respondingENAMEf rom thetablesDEPARTMENTand
EMPLOYEE.Hi nt:HODoft heDEPARTMENTt ableshoul dbemat chedwithENOof
theEMPLYEEt ableforgetti
ngthedesiredresult 2
i
ii) Todi spl
ayENAME, SALARY, ZONEandI NCOMETAX( Note: I
ncomeTaxt obe
calculat
edas30%ofsal ary)ofal
ltheempl oyeeswi t
happr opri
atecol
umn
headings. 2
c)InadatabaseSTUDENT, therei
saTabl eRESULTwi t
ht hefollowingcontent
s:
Table:RESULT
REGNO NAME MARKS SECTIO CLASSTEAC ADMNO
N HER

10004 Mohi
t 90 A Ms.Nat
hani Z101

10211 Mukt
a 85 B Mr
.Gokhl
e Z109

10923 Mohi
t 92 B Mr
.Gokhl
e Z120

10313 Sana 80 A Ms.Nat


hani Z234

i
) I
denti
fyt
heatt
ribut
es,whichcanbechosenasCandi
dat
ekeysinthet
abl
eRESULT.
1
i
i
) Wri
teMySqlquerytochangetheMarksofMukt
ato95inthet
ableRESULT.
1

Page6/
6

You might also like