You are on page 1of 26

ATMARAM SANATAN

DHARMACOLLEGE
(
Uni
ver
sit
yofDel
hi)

DATABASE
MANAGEMENT
SYSTEM
PRACTI
CALFI
LE
2019-
2020

Submi
ttedt
o-Mr
.ManujAggar
wal
Submi
ttedby-
MadhuShar
ma
Rol
lno.
-(19/
77009)
BSc
.(H)Mat
hss
ec-
A
I
NDEX
1.Cr eateadat abasehav i
ngt wot ableswi t
ht hespecifi
edf iel
ds,tocomput er
izeal i
brar
y
system ofaDel hi Univer
sit
yCol lege.
Librar yBooks(Accessi onnumber ,Titl
e, Author,
Department ,PurchaseDate,Pri
ce)
IssuedBooks( Accessi onnumber ,Borrower )
a)Ident i
fypri
mar yandf or
eignkey s.Cr eatethetabl
esandi nsertatleast5r ecordsineach
table.
b)Del etetherecordofbookt i
tled“ DatabaseSy stem Concept s”.
c)Changet heDepar tmentoft hebookt i
tl
ed“ Di
scret
eMat hs”to“CS”.
d)Li stallbookst hatbelongt o“ CS”depar t
ment .
e)Listal lbookst hatbelongt o“CS”depar t
mentandar ewr it
tenbyaut hor“Navathe”.
f)Listal lcomputer( Depart
ment=“ CS” )thathavebeeni ssued.
g)Li stallbookswhi chhav eapr icelesst han500orpur chasedbet ween“ 01/01/1999”
and“ 01/01/2004” .

2.Cr eateadat abasehav ingt hreet ablest ost oret hedet ai


lsofst udentsofComput er
Depar t
menti ny ourcol lege,aspert hegi venschema.
Personal i
nformat ionaboutSt udent( Colleger ol
lnumber ,Nameofst udent,
Dateofbirth,
Addr ess, Marks( roundedof ftowhol enumber )inpercent ageat10+2, Phonenumber )
PaperDet ail
s( Papercode, Nameoft hePaper )
Student ’
sAcademi candAt tendancedet ails(Coll
eger ol
l number ,Papercode,
Attendance, Marksi nhomeexami nation).
a)Ident i
fyprimar yandf oreignkey s.Cr eat et
het abl
esandi nsertatleast5recordsineach
table.
b)Desi gnaquer ythatwi llreturnt her ecor ds(fr
om thesecondt abl
e)alongwiththenameof
studentf rom thef irsttable,r elatedt ost udentswhohav emor et han75% attendanceand
mor et han60%mar ksinpaper2.
c)Listal lstudentswhol i
vei n“ Delhi”andhav emar ksgr eaterthan60i npaper1.
d)Fi ndt hetotalattendanceandt otal mar ksobtainedbyeachst udent.
e)Listt henameofst udentwhohasgott hehi ghestmar ksi npaper2.

3.Createt hefoll
owi ngtablesandanswert hequer i
esgi
venbelow:
Customer( CustI
D, emai l
,Name, Phone, Ref errerID)
Bicycle(BicycleI
D, DatePurchased, Col
or ,Cust ID,Model
No)
BicycleModel (Model No,Manuf acturer,Style)
Service(StartDate,Bicycl
eID,EndDat e)
a)Identif
ypr imaryandf oreignkey s.Creat ethet abl
esandinsertatleast5recor
dsi
n
eacht able.
b)Listallthecust omer swhohav ethebi cyclesmanuf act
uredbymanuf act
urer
“Honda” .
c)Listthebi cycl
espur chasedbyt hecust omer swhohav ebeenr eferr
edbycustomer
“C1”.
d)Listthemanuf acturerofredcol oredbi cycles.
e)Listthemodel soft hebicycl
esgi venf orser vice.

4.Cr
eatethefoll
owingtables,enteratleast5recor
dsi
neacht
abl
eandanswert
hequer
ies
gi
venbelow.
EMPLOYEE(Per son_Name, Str
eet,Cit
y)
WORKS(Per son_Name, Company _Name, Sal
ary)
COMPANY(Company _
Name, City)
MANAGES(Per son_Name, Manager _Name)
a)I
dent
ifypr
imaryandf orei
gnkey s.
b)Altertabl
eempl oyee,addacol umn“ emai l
”oft ypevarchar(
20).
c)Findthenameofal lmanager swhowor kforbot hSambaBankandNCBBank.
d)Findthenames, streetaddressandci ti
esofr esidenceandsalaryofal
lemploy
ees
whowor kfor“SambaBank”andear nmoret han$10, 000.
e)Findthenamesofal lemployeeswhol i
veint hesameci t
yasthecompanyfor
whichtheywor k.
f)Fi
ndt hehighestsalary,
lowestsalaryandav er agesalarypai
dbyeachcompany .
g)Findthesum ofsal aryandnumberofempl oyeesi neachcompany .
h)Fi
ndthe
nameoft hecompanyt hatpayshi ghestsalary.

5.Cr eatet hef oll


owingt ables,ent eratleast5r ecordsi neacht ableandanswert hequer
ies
givenbel ow.
Suppl i
er s(SNo, Sname, Stat us,SCi t
y)
Parts( PNo, Pname, Col our,Wei ght ,
City)
Project( JNo, Jname, Jcity)
Shipment( Sno, Pno,Jno, Qunat ity)
a)Ident if
ypr imar yandf oreignkey s.
b)Getsuppl i
ernumber sf orsuppl iersinPariswi t
hst atus>20.
c)Getsuppl i
ersdet ail
sf orsuppl i
erswho suppl ypar tP2.Di spl
ayt he suppli
erl
istin
i
ncr easingor derofsuppl iernumber s.
d)Getsuppl i
er snamesf orsuppl ierswhodonotsuppl ypartP2.
e)Foreachshi pmentgetf ullshipmentdet ail
s, i
ncludingtotalshi
pmentwei ghts.
f)Getal l t
heshi pment swher ethequant it
yisi ntherange300t o750i ncl
usi
ve.
g)Getpar tnos.f orpartst hatei t
herwei ghmor ethan16poundsorar esuppli
edbysuppli
ers
S2, orbot h.
h)Gett henamesofci tiest hatstor emor ethanf i
ver edparts.
i
)Getf ulldet ail
sofpar tssuppl iedbyasuppl ierinLondon.
j
)Getpar tnumber sforpar tsuppl iedbyasuppl i
erinLondont oapr oj
ectinLondon.
k)Gett het otal numberofpr ojectsuppl i
edbyasuppl i
er(say,S1).
l
)Gett het otal quantit
yofapar t(say,P1)suppl i
edbyasuppl ier(say,
S1).
PRACTI
CALS
1.Cr eateadatabasehav i
ngtwot ableswiththespeci
fi
edfiel
ds,tocomputeri
zeal
i
brar
y
system ofaDelhiUniv
ersi
tyCol
lege.
LibraryBooks(
Accessionnumber,Tit
le,Aut
hor,
Department
,PurchaseDat
e,Pr
ice)
IssuedBooks(Accessi
onnumber ,Borrower
)

a)Ident
if
ypr i
mar
yandf
orei
gnkey
s.Cr
eat
ethet
abl
esandi
nser
tatl
east5r
ecor
dsi
n
eachtable.

b)Del
etet
her
ecor
dofbookt
it
led“
Dat
abaseSy
stem Concept
s”.

c)Changet
heDepar
tmentoft
hebookt
it
led“
Discr
eteMat
hs”t
o“CS”
.

d)Li
stal
lbookst
hatbel
ongt
o“CS”depar
tment
.

e)Li
stal
lbookst
hatbel
ongt
o“CS”depar
tmentandar
ewr
it
tenbyaut
hor“
Nav
athe”
.

f
)Li
stal
lcomput
er(
Depar
tment=“
CS”
)thathav
ebeeni
ssued.

g)Li
stal
lbookswhichhav
eapr
icel
esst
han500orpur
chasedbet
ween“
01/
01/
1999”
and“01/
01/2004”
.

Sol
uti
on:
Dat
abase:

cr
eat
edat
abasedul
i
b;

Tabl
e:

creat etablelibrar
ybooks(
accessi on_ noint(
5)NOTNULL,
ti
tlev archar(20),
aut horv archar(
20),
depar tmentv ar
char(
20),
dopDATE,
pricei nt);

createt
abl
eissuedbooks(
accessi
on_noint(
5),
borrowerv
archar(10),
forei
gnkey(accession_no)r
efer
encesl
i
brar
ybooks(
accessi
on_
no)
);

I
nser
tval
uesi
ntabl
es:

I
nsertI
ntol
ibrar
y books
Val
ues(101,
'DatabaseSy st
em Concepts'
,
'Navat
he'
,
'CS'
,'
1997-
10-
02'
,
150)
;
I
nsertI
ntol
ibrar
y books
Val
ues(102,
'CMC' ,
'Ani
ta'
,
’Di
scr
eteMat hs'
,
'1999-
07-
02',
450)
I
nsertI
ntol
ibrar
ybooks
Val
ues(103,
'ABC',
'
Aman' ,
'
Hindi'
,
'1999-07-
21',
400);
I
nsertI
ntol
ibrar
ybooks
Val
ues(104,
'EngWord',
'
Ravi'
,
'Engli
sh'
,'
2000-10-01'
,
700);
I
nsertI
ntol
ibrar
ybooks
Val
ues(105,
'ABC12',
'
Ramesh' ,
'
Hindi'
,'
2000-09-
21',
300)
;

I
nsertI
ntoi
ssuedbooks
Val
ues(102,

Sonia’)
;
I
nsertI
ntoi
ssuedbooks
Val
ues(103,
'
Rit
u’);
I
nsertI
ntoi
ssuedbooks
Val
ues(104,
'
Ami sh’
);
I
nsertI
ntoi
ssuedbooks
Val
ues(105,
'
Raju’)
;
I
nsertI
ntoi
ssuedbooks
Val
ues(101,
'
Mohi t
’)
;

t
abl
eli
brar
ybooks:
-

t
abl
eissuedbooks:
-

Ansa.

Li
brar
ybookspr
imar
ykey(
accessi
on_
no)

I
ssuedbooksf
orei
gnkey(
accessi
on_
no)
Ans(
b).

del
etef
rom l
i
brar
ybooks

wher
eti
tl
e="
Dat
abaseSy
stem Concept
s";

Ans(
c).

updat
eli
brar
ybooks

setdepar
tment
="CS"

wher
edepar
tment
="Di
scr
eteMat
hs"
;

Ans(
d).

sel
ect*f
rom l
i
brar
ybooks

wher
edepar
tment
="CS"
;

Ans(
e).

sel
ect*f
rom l
i
brar
ybooks

wher
edepar
tment
="CS"andaut
hor
="Nav
athe"
;
Ans(
f).

sel
ect*

f
rom l
i
brar
ybooksasl
,issuedbooksasi

wher
el.
accessi
on_
no=i
.accessi
on_
noanddepar
tment="
CS"
;

Ans(
g).

Sel
ect*

Fr
om l
i
brar
ybooks

Wher
epr
ice<500ordopbet
ween“
1999-
01-
01”and“
2004-
01-
01”
;

2.Createadatabasehav ingthreetablest ost


orethedetailsofst
udentsofComputer
Departmentinyourcollege,asperthegi venschema.
Personalinf
ormat i
onaboutSt udent(Collegerol
lnumber, Nameofstudent,Dat
eofbi
rth,
Address,Marks(
r oundedofftowhol enumber )inpercentageat10+2, Phonenumber)
PaperDet ai
l
s(Papercode, Nameoft hePaper )
Student’
sAcademi candAt tendancedet ail
s(Coll
egeroll
number ,Papercode,
Attendance,Marksinhomeexami nation).

a)Ident
if
ypr i
mar
yandf
orei
gnkey
s.Cr
eat
ethet
abl
esandi
nser
tatl
east5r
ecor
dsi
n
eachtable.

b)Designaquer
ythatwil
lretur
nt herecords(f
rom t
hesecondt
abl
e)al
ongwitht
he
nameofstudentf
rom t
hefirsttable,r
elat
edtostudent
swhohavemorethan75%
att
endanceandmorethan60%mar ksinpaper2.

c)Li
stal
lst
udent
swhol
i
vei
n“Del
hi”andhav
emar
ksgr
eat
ert
han60i
npaper1.

d)Fi
ndt
hetot
alat
tendanceandt
otal
marksobtai
nedbyeachstudent
.
e)Li
stt
henameofstudentwhohasgott
hehighestmar
ksinpaper2.
SOLUTI
ON:
Cr
eat
eDat
abase:

Cr
eat
edat
abasecol
l
ege;

Cr
eat
eTabl
es:

createtabl est udentinf


o(
crollv
ar char (5)NOTNULL,
namev archar (20),
dobDATE,
addressv ar char (
30),
mar ksv archar (30),
phonenoi nt(10) ,
primarykey (croll
));

createtabl
epaper (
paper_codev archar (
5)NOTNULL,
paper_namev archar(20),
croll
varchar(5),
primarykey(paper _code),
forei
gnkey (
cr ol
l)referencesst
udent
inf
o(cr
oll
))
;

createt abl
eacademi c_detai
ls(
crollvarchar(5),
paper _codev archar(5),
attendancei nt(5),
mohi nt(3)
,
primar ykey(croll
,paper _code),
foreignkey (
cr ol
l)referencesst udent
inf
o(crol
l
),
foreignkey (
paper _code)r eferencespaper(
paper
_code)
);

I
nsertValues:
i
nserti
ntostudenti
nfo
v
alues("
A101",
"Mohi t
",
"1989-05-16",
'Delhi'
,
75,8978546921);
i
nserti
ntostudenti
nfo
v
alues("
A102",
"Parul"
,"
1989-10-12",'
Mumbai '
,
80,9638527413);
i
nserti
ntostudenti
nfo
v
alues("
A103",
"Sanjay",
"1989-07-18",
'Delhi
',
50,7418529637);
i
nserti
ntostudenti
nfo
v
alues("
A104",
"Viv
ek","1989-03-30",
'
Chandi garh'
,30,
7894561231)
;
i
nserti
ntostudenti
nfo
v
alues("
A105",
"Arj
un","
1989-08-22" ,
'
Delhi',
60,
7854123698) ;
i
nserti
ntopaper
v
alues("P101"
,"
P1"
,"
A101"
);
i
nserti
ntopaper
v
alues("P102"
,"
P2"
,"
A102"
);
i
nserti
ntopaper
v
alues("P103"
,"
P3"
,"
A103"
);
i
nserti
ntopaper
v
alues("P104"
,"
P4"
,"
A104"
);
i
nserti
ntopaper
v
alues("P105"
,"
P5"
,"
A105"
);

i
nserti
ntoacademic_det
ail
s
v
alues(
'A101'
,'
P101'
,70,
85);
i
nserti
ntoacademic_det
ail
s
v
alues(
'A102'
,'
P102'
,92,
75);
i
nserti
ntoacademic_det
ail
s
v
alues(
'A103'
,'
P103'
,88,
80);
i
nserti
ntoacademic_det
ail
s
v
alues(
'A104'
,'
P104'
,93,
70);
i
nserti
ntoacademic_det
ail
s
v
alues(
'A105'
,'
P105'
,50,
90);

Ansa.

St
udenti
nfo:
Pri
mar
yKey(
crol
l
)

Paper
:Pr
imar
yKey
(paper
_code)
,For
eignKey(
crol
l
)

At
tendanceDet
ail
s:Pr
imar
yKey
(cr
oll
,
paper
_code)
,For
eignKey(
crol
l
,paper
_code)
Ansb.

sel
ectname,
paper
_namef
rom st
udent
inf
oass,
academi
c_det
ail
sasa,
paperasp

wher
ea.
att
endance>75andmoh>60andp.
paper
_name="
P2"ands.
crol
l
=p.
crol
land

p.
paper
_code=a.
paper
_code;

Ansc.

selectname
fr
om paperasp, st
udentinfoass,academi
c_detai
lsasa
wher es.
address="Del
hi"andp.paper_
name="P2"anda.
moh>60ands.
crol
l=p.
crol
land
p.paper_code=a.paper_code;

Ansd.

sel
ectsum(academic_det
ail
s.moh)as'
Tot
alMar
ks'
,Sum(
academi
c_det
ail
s.at
tendance)
fr
om academic_det
ail
s;

Anse.
sel
ectstudenti
nfo.name,max(a.
moh)
fr
om studenti
nfo,academi c_
det
ail
sasa,paper
wherestudenti
nfo.croll
=paper.
crol
landa.paper
_code=paper
.paper
_codeand
paper
.paper_name=" P2";

3.Creat
ethefoll
owingtablesandanswert hequeri
esgi
venbel
ow:
Customer(CustI
D,emai l
,Name, Phone,Referr
erI
D)
Bicy
cle(Bi
cycleI
D,DatePurchased,Color,
CustID,Model
No)
Bicy
cleModel(ModelNo,Manuf act
urer,Sty
le)
Servi
ce(St
artDate,
Bicycl
eID,EndDate)

a)Ident
if
ypr i
mar
yandf
orei
gnkey
s.Cr
eat
ethet
abl
esandi
nser
tatl
east5r
ecor
dsi
n
eachtable.

b)Li
stal
lthecust
omer
swhohav
ethebi
cycl
esmanuf
act
uredbymanuf
act
urer


Honda”
.
c)Li
stt
hebi
cycl
espur
chasedbyt
hecust
omer
swhohav
ebeenr
efer
redbycust
omer“
C1”
.

d)Li
stt
hemanuf
act
urerofr
edcol
oredbi
cycl
es.

e)Li
stt
hemodel
soft
hebi
cycl
esgi
venf
orser
vice.

Sol
uti
on:
Cr
eat
edat
abasebi
cycl
e_company
;

Cr
eat
eTabl
e:

cr
eat
etabl
ecust
omer
(

c_
cidv
archar
(5)pr
imar
ykey
,

emai
lvar
char
(30)
,

namev
archar
(20)
,

phonei
nt(
10)
,

r
efer
_idv
archar
(20)
);

cr
eat
etabl
ebi
cycl
emodel
(

bmodel
_nov
archar
(5)pr
imar
ykey
,

manuf
act
urerv
archar
(30)
,

st
ylev
archar
(20)
,

c_
cidv
archar
(5)
,

f
orei
gnkey(
c_ci
d)r
efer
encescust
omer
(c_
cid)
);

cr
eat
etabl
ebi
cycl
e(

b_
idv
archar
(5)pr
imar
ykey
,

pur
chase_
dat
eDATE,

c_
cidv
archar
(5)
,

model
_nov
archar
(10)
,

f
orei
gnkey(
b_i
d)r
efer
encescust
omer
(c_
cid)
,

f
orei
gnkey(
model
_no)r
efer
encesbi
cycl
emodel
(bmodel
_no)
);
cr
eat
etabl
eser
vice(

bi
cycl
e_i
dvar
char
(10)pr
imar
ykey
,

st
art
_dat
eDATE,

end_
dat
eDATE,

f
orei
gnkey(
bicy
cle_
id)r
efer
encesbi
cycl
e(b_
id)
);

I
nser
tVal
ues:

i
nser
tint
ocust
omer

v
alues(
"C101"
,"
abc@gmai
l
.com"
,"
Ram"
,7418529637,
"C1"
);

i
nser
tint
ocust
omer

v
alues(
"C102"
,"
bcd@gmai
l
.com"
,"
Vinay
",
7894561237,
"C1"
);

i
nser
tint
ocust
omer

v
alues(
"C103"
,"
cde@gmai
l
.com"
,"
Ami
t"
,9638527413,
"C5"
);

i
nser
tint
ocust
omer

v
alues(
"C104"
,"
def
@gmai
l
.com"
,"
Bhushan"
,9873216543,
"C3"
);

i
nser
tint
ocust
omer

v
alues(
"C105"
,"
fi
g@gmai
l
.com"
,"
Sanj
ay"
,7419638527,
"C4"
);

i
nser
tint
obi
cycl
emodel

v
alues(
"M101"
,"
Honda"
,"
GS"
,"
C101"
);

i
nser
tint
obi
cycl
emodel

v
alues(
"M102"
,"
Tat
a",
"S"
,"
C102"
);
i
nser
tint
obi
cycl
emodel

v
alues(
"M103"
,"
Toy
ota"
,"
GS"
,"
C103"
);

i
nser
tint
obi
cycl
emodel

v
alues(
"M104"
,"
Honda"
,"
S",
"C105"
);

i
nser
tint
obi
cycl
emodel

v
alues(
"M105"
,"
Maur
ti
",
"S"
,"
C102"
);

i
nser
tint
obi
cycl
e

v
alues(
"B101"
,"
2003-
10-
13"
,"
C102"
,"
M101"
,"
red"
);

i
nser
tint
obi
cycl
e

v
alues(
"B102"
,"
2007-
10-
13"
,"
C102"
,"
M101"
,"
red"
);

i
nser
tint
obi
cycl
e

v
alues(
"B103"
,"
2006-
10-
13"
,"
C102"
,"
M101"
,"
blue"
);

i
nser
tint
obi
cycl
e

v
alues(
"B104"
,"
2005-
10-
13"
,"
C104"
,"
M104"
,”
black”
);

I
nser
tint
obi
cycl
e

v
alues(
"B105"
,"
2004-
10-
13"
,"
C105"
,"
M105"
,"
pur
ple"
);

i
nser
tint
oser
vice

v
alues(
"B101"
,"
2005-
12-
13"
,"
2008-
12-
13"
);

i
nser
tint
oser
vice

v
alues(
"B102"
,"
2009-
12-
13"
,"
2010-
12-
13"
);

i
nser
tint
oser
vice

v
alues(
"B103"
,"
2008-
12-
13"
,"
2009-
12-
13"
);
i
nser
tint
oser
vice

v
alues(
"B104"
,"
2003-
12-
13"
,"
2010-
12-
13"
);

i
nser
tint
oser
vice

v
alues(
"B105"
,"
2005-
12-
13"
,"
2008-
12-
13"
);

Ansa.

Cust
omerpr
imar
ykey(
c_ci
d)

Bi
cycl
emodel
(bmodel
_no)andf
orei
gnkey(
c_ci
d)

Bi
cycl
e(b_
id)andf
orei
gnkey
(b_
cidandbmodel
_no)

Ser
vicepr
imar
ykey(
bicy
cle_
id)andf
orei
gnkey(
bicy
cle_
id)

Ansb.

sel
ectnamef
rom cust
omerasc,
bicy
clemodel
asb

wher
eb.
manuf
act
urer="
Honda"andb.
c_ci
d=c.
c_ci
d;

Ansc.

sel
ectb.
b_i
dfr
om cust
omerasc,
bicy
cleasb

wher
ec.
ref
er_
id="
C1"andb.
c_ci
d=c.
c_ci
d;
Ansd.
sel
ectdi
sti
nctbm.manufact
urerf
rom bi
cycl
emodelasbm ,
bicy
cleasb
whereb.
color="
red"andb.model
_no=bm. bmodel
_no;

Anse.
sel
ectdi
stinctb.
model
_nofr
om bi
cycl
emodel
asbm ,
bicy
cleasb,
ser
viceass
wheres.
bicycle_
id=b.
b_i
dandb.model
_no=bm.
bmodel_
no;

4.Cr
eatethefoll
owingtables,enteratleast5recor
dsi
neacht
abl
eandanswert
hequer
ies
gi
venbelow.
EMPLOYEE(Per son_Name, Str
eet,Cit
y)
WORKS(Per son_Name, Company _Name, Sal
ary)
COMPANY(Company _
Name, City)
MANAGES(Per son_Name, Manager _Name)

a)I
dent
if
ypr
imar
yandf
orei
gnkey
s.

b)Al
tert
abl
eempl
oyee,
addacol
umn“
emai
l
”oft
ypev
archar
(20)
.

c)Fi
ndt
henameofal
lmanager
swhowor
kforbot
hSambaBankandNCBBank.

d)Fi
ndt
henames,
str
eetaddr
essandci
ti
esofresi
denceandsal
aryofal
lempl
oyees
whowor
kfor“
SambaBank”andear
nmorethan$10,000.

e)Findthenamesofal
lempl
oyeeswhol
i
vei
nthesameci
tyast
hecompanyf
or
whichtheywork.

f
)Fi
ndt
hehi
ghestsal
ary
,lowestsal
aryandav
eragesal
arypai
dbyeachcompany
.

g)Fi
ndt
hesum ofsal
aryandnumberofempl
oyeesi
neachcompany
.

h)Fi
ndt
henameoft
hecompanyt
hatpay
shi
ghestsal
ary
.

Sol
uti
on:
Cr
eat
edat
abasebi
g_comp;

Cr
eat
etabl
es:

createtableemployee
(person_namev archar
(10)pr
imar
ykey
,
streetvarchar(
20),
cit
yv archar(
20));

createtableworks
(person_namev ar
char (
10),
company _namev archar(20)
,
Salaryint
,
forei
gnkey( per
son_ name)refer
encesempl
oyee(
per
son_
name)
);

creat
et abl
ecompany
(company _
namev archar(
10)pri
marykey,
cit
yv ar
char(20)
,
forei
gnkey( company_name)ref
erenceswor
ks(
company
_name)
);

createtablemanages
(person_namev archar(
10)pri
mar ykey
,
manager _namev archar(
20),
forei
gnkey( per
son_ name)refer
encesempl
oyee(
per
son_
name)
);

I
nser
tval
ues

i
nserti
ntoempl oyee
v
alues("Ravi
",
"S1",
"Delhi
");
i
nserti
ntoempl oyee
v
alues("Aamish",
"S4",
"Chennai")
;
i
nserti
ntoempl oyee
v
alues("Manoj",
"S3",
"Delhi"
);
i
nserti
ntoempl oyee
v
alues("Rakesh",
"S3",
"Delhi"
);
i
nserti
ntoempl oyee
v
alues("Bhuvan",
"S2",
"Chennai")
;

i
nserti
ntoworks
v
alues('
Ravi
'
,'
NCBBank',
20000);
i
nserti
ntoworks
v
alues('
Aamish'
,'
SambaBank',
25000);
i
nserti
ntoworks
v
alues('
Aamish'
,'
NCBBank'
,22000);
i
nserti
ntoworks
v
alues('
Manoj'
,'
NCBBank'
,20000);
i
nserti
ntoworks
v
alues('
Rakesh'
,'
Kot
ak'
,
15000);
i
nserti
ntoworks
v
alues('
Bhuvan'
,'
SambaBank',
10000)
;

i
nserti
ntocompany
v
alues('
NCBBank','
Delhi'
);
i
nserti
ntocompany
v
alues('
SambaBank','Chennai
')
;
i
nserti
ntocompany
v
alues('
Kotak'
,'
Delhi
'
) ;
i
nserti
ntocompany
v
alues('
SBIBank'
,'
Jaipur'
);
i
nserti
ntocompany
v
alues('
PNBBank','
Chandigarh'
);

i
nserti
ntomanages
v
alues('
Rakesh'
,'
Baman');
i
nserti
ntomanages
v
alues('
Bhuvan'
,'
Jack'
);
i
nserti
ntomanages
v
alues('
Manoj'
,'
Jack'
);
i
nserti
ntomanages
v
alues('
Ravi
',
'
Jacy')
;
i
nserti
ntomanages
v
alues('
Aamish'
,'
Saurabh'
);
Ansa.
Employ
eepr i
marykey(person_name)
Worksfor
eignkey(per
son_ name)
Companyprimarykey(company _name)andfor
eignkey
(company
_name)
Managesprimarykeyandf orei
gnkey(person_name)

Ansb.
al
tert
abl
emanages
addemai
lvar
char
(20)
;

Ansc
sel
ectmanager_namefr
om manages
whereperson_
namei n(
sel
ectper
son_
namef
rom wor
kswher
ecompany
_name="
Samba
Bank"orcompany_name="
NCBBank");

Ansd
sel
ecte.
per
son_
name,e.
street
,e.
cit
y,w.
sal
aryf
rom employ
eease,wor
ksasw
wheree.
per
son_
name=w.person_nameandcompany _
name="SambaBank"andsal
ary
>10000;

Anse.
sel
ecte.
per
son_namefr
om employeease,
worksasw,companyasc
wheree.
per
son_name=w.
person_
nameandc.company
_name=w.company
_nameand
c.
cit
y=e.ci
ty;
Ansg.
selectc.
company_name,
sum(w.sal
ary
),count
(w.
per
son_
name)f
rom empl
oyeease,
wor
ks
asw, companyasc
wher ec.
company_name=w.company_name
groupbyc.company_name;

Ansf
selectc.
company_name,
max(w.sal
ary
),mi
n(w.
sal
ary
),av
g(w.
sal
ary
)fr
om wor
ksasw,
companyasc
wher ec.
company_name=w.company_name
groupbyc.company_name;

Ansh.
selectc.
company_namefr
om worksasw,companyasc
wher ec.
company_name=w.company_
name
orderbyw.sal
arydescl
imi
t1;

5.Cr eatethefol
lowi
ngt ables,enteratleast5r
ecor
dsi
neacht
abl
eandanswert
hequer
ies
gi
v enbel ow.
Suppl i
ers(SNo,Sname, Status,SCity)
Parts( PNo,Pname,Col our,Weight,Cit
y)
Project(JNo,Jname, Jcit
y)
Shipment( Sno,Pno,Jno, Qunatit
y)

a)Identif
yprimar yandf oreignkey s.
b)Getsuppl i
ernumber sf orsuppl iersinPar iswi t
hst atus>20.
c)Getsuppl iersdet ai
lsf orsuppl i
erswho suppl ypar tP2.Di spl
ayt he suppl
i
erl
i
sti
n
i
ncreasingor derofsuppl iernumber s.
d)Getsuppl i
er snamesf orsuppl ierswhodonotsuppl ypartP2.
e)Foreachshi pmentgetf ullshipmentdet ail
s, i
ncludingtotalshi
pmentwei ghts.
f)Getalltheshi pmentswher et hequant i
tyisi nther ange300t o750i ncl
usi
ve.
g)Getpar tnos.f orpart
st hatei therwei ghmor et han16poundsorar esuppliedby
suppli
ersS2, orbot h.
h)Gett henamesofci ti
est hatstor emor et hanf i
v eredparts.
i
)Getf ulldet
ailsofpar t
ssuppl iedbyasuppl ierinLondon.
j
)Getpar tnumber sforpar tsuppl iedbyasuppl i
eri nLondont oapr oj
ectinLondon.
k)Getthet otal numberofpr ojectsuppl i
edbyasuppl i
er(say,S1)
.
l
)Gett het ot
al quanti
tyofapar t(say,P1)suppl i
edbyasuppl ier(
say ,
S1).
SOLUTI
ON.

Createdat
abasecompany
_bi
g;
Table:

createtablesuppl i
ers(
snov archar(5)primarykey
,
snamev archar(20),
statusint(5)
,
scit
yv archar(10));

createtablepar ts(
pnov archar(5)pr i
marykey
,
pnamev archar(20),
pcolorvarchar (
20) ,
pweightf l
oat(5),
pcit
yv archar(30));

cr
eat
etabl
epr
oject
(

j
nov
archar
(5)pr
imar
ykey
,

j
namev
archar
(20)
,

j
cit
yvar
char
(20)
);

cr
eat
etabl
eshi
pment
(

s_
snov
archar
(5),

s_
pnov
archar
(5)
,

s_
jnov
archar
(5)
,

Quant
it
yint
,

pr
imar
ykey
(s_
sno,
s_j
no,
s_pno)
,

f
orei
gnkey
(s_
sno)r
efer
encessuppl
i
ers(
sno)
,

f
orei
gnkey
(s_
pno)r
efer
encespar
ts(
pno)
,

f
orei
gnkey
(s_
jno)r
efer
encespr
oject
(j
no)
);
I
nser
tVal
ues:

i
nser
tint
osuppl
i
ers

v
alues(
"S101"
,"
S1"
,18,
"NewYor
k")
;

i
nser
tint
osuppl
i
ers

v
alues(
"S102"
,"
S2"
,20,
"London"
);

i
nser
tint
osuppl
i
ers

v
alues(
"S103"
,"
S3"
,25,
"Par
is"
);

i
nser
tint
osuppl
i
ers

v
alues(
"S104"
,"
S4"
,28,
"London"
);

i
nser
tint
osuppl
i
ers

v
alues(
"S105"
,"
S5"
,30,
"Par
is"
);

i
nser
tint
opar
ts

v
alues(
"p101"
,"
p1"
,"
orange"
,18,
"NewYor
k")
;

i
nser
tint
opar
ts

v
alues(
"p102"
,"
p2"
,"
whi
te"
,16,
"London"
);

i
nser
tint
opar
ts

v
alues(
"p103"
,"
p3"
,"
yel
l
ow"
,15,
"London"
);

i
nser
tint
opar
ts

v
alues(
"p104"
,"
p4"
,"
pink"
,11,
"London"
);

i
nser
tint
opar
ts

v
alues(
"p105"
,"
p5"
,"
red"
,20,
"Par
is"
);
i
nser
tint
opr
oject

v
alues(
"j
101"
,"
mai
n",
"NewYor
k")
;

i
nser
tint
opr
oject

v
alues(
"j
102"
,"
act
ion"
,"
London"
);

i
nser
tint
opr
oject

v
alues(
"j
103"
,"
not
hing"
,"
Par
is"
);

i
nser
tint
opr
oject

v
alues(
"j
104"
,"
zoom"
,"
London"
);

i
nser
tint
opr
oject

v
alues(
"j
105"
,"
game"
,"
Par
is"
);

Ansa

Suppl
i
erPr
imar
ykey(
sno)

Par
tsPr
imar
yKey
(pno)

Pr
ojectPr
imar
yKey
(jno)

Shi
pmentPr
imar
yKey
(s_
sno,
s_pno,
s_j
no),
For
eignKey(
sno,
pno,
j
no)
Ansb.

sel
ectsno,
stat
us

f
rom suppl
i
ers

wher
esci
ty="
Par
is"andst
atus>20;

Ansc.

sel
ects.
sno,
s.
sname

f
rom suppl
i
ersass,
par
tsasp,
shi
pmentassp

wher
ep.
pname="
p2"ands.
sno=sp.
s_sno

or
derbysnodesc;

Ansd.

sel
ects.
sno,
s.
sname

f
rom suppl
i
ersass,
par
tsasp,
shi
pmentassp

wher
enot(
p.pname="
p2"
)ands.
sno=sp.
s_snoandp.
pno=sp.
s_pno;
Anse.

sel
ectsp.
s_sno,
sp.
s_pno,
sp.
s_j
no,
p.pwei
ght*sp.
quant
it
yas"
shi
pment
"

f
rom par
tsasp,
shi
pmentassp

wher
ep.
pno=sp.
s_pno;

Ansf
.

sel
ect*

f
rom shi
pmentassp

wher
equant
it
ybet
ween300and750;

Ansg.

sel
ectp.
pno

f
rom par
tsasp,
shi
pmentassp

wher
e(p.
pwei
ght>16orsp.
s_sno="
S102")
andp.
pno=sp.
s_pno;

Ansh.

sel
ectp.
pci
ty

f
rom par
tsasp,
shi
pmentassp

wher
ep.
pcol
or="
red"andsp.
quant
it
y>5andp.
pno=sp.
s_pno;
Ansi
.

sel
ectp.
pno,
p.pname,
p.pcol
or,
p.pci
ty,
p.pwei
ght

f
rom par
tsasp,
shi
pmentassp,
suppl
i
ersass

wher
es.
sci
ty="
Par
is"andp.
pno=sp.
s_pnoandsp.
s_sno=s.
sno;

Ansj

sel
ectp.
pno

f
rom par
tsasp,
shi
pmentassp,
suppl
i
ersass,
proj
ectaspj

wherep.
pcit
y="London"ands.
sci
ty="
Par
is"andp.
pno=sp.
s_pnoandsp.
s_sno=s.
snoand
pj
.j
no=sp.s_j
no;

Ansk.

sel
ectcount
(pj
.j
no)

f
rom shi
pmentassp,
suppl
i
ersass,
proj
ectaspj

wher
es.
sname="
S101"andsp.
s_sno=s.
snoandpj
.j
no=sp.
s_j
no

gr
oupbypj
.j
no;
Ansl
.

sel
ectsum(
sp.
quant
it
y)

f
rom par
tsasp,
shi
pmentassp,
suppl
i
ersass

wher
ep.
pno="
p1"ands.
sname="
S1"

gr
oupbysno;

You might also like