Anda di halaman 1dari 99

GURU NANAK Engineering College

Ibrahimpatnam, R R District 501 50 !A" #"$

Department o% Comp&ter 'cience Engineering Database (anagement ')stems *ab (an&al +C' 0515,II . /ech I 'emester +.ranch0 C'EIN'/RUC/1R' 0

(r" Rishi 'a)al, 21D (r" 'ai3&l&, Asst" #ro%"

Document NO:

Date of Issue:

Compiled b

Aut!o"i#ed b

GNEC/CSE/LAB MANUAL/DBMS
Date of "e$ision %e"ified b

#R1GRA((ER'

1" K"Ra4i 5" /ri4eni 6oshi

DBMS Lab Manual

INDE7

'" No & ) ( ( * 5 . / 4 ; &=

Contents Lab Ob'ecti$e Int"oduction About Lab Standa"d Ope"atin+ ,"ocedu"e SO, Guidelines to Students Desc"iption about S0L1 ,L/S0L statements and D)23 List of Lab E6e"cises *3& S llabus ,"o+"ams 78N9U: *3) Additional ,"o+"ams Bac<+"ound 9!eo" Solutions fo" ,"o+"ams ,L>S?l ,"o+"ams Additional %i$a 0uestion @efe"ences

#age" no ( * . / 4 ; &* )= 5= 44 ;*

K.Ravi

DBMS Lab Manual

*A. 1.6EC/I8E
Upon successful completion of t!is Lab t!e student Aill be able to: C"eatin+ database ob'ects Modif in+ database ob'ects Manipulatin+ t!e data @et"ie$in+ t!e data f"om t!e database se"$e" ,e"fo"min+ database ope"ations in a p"ocedu"al manne" usin+ pl/s?l ,e"fo"min+ database ope"ations 7c"eate1 update1 modif 1 "et"ie$e1 etc31: usin+ f"ont>end tools li<e D)23 Desi+n and De$elop applications li<e ban<in+1 "ese"$ation s stem1 etc31

K.Ravi

DBMS Lab Manual

IN/R1DUC/I1N A.1U/ *A.

9!e"e a"e .. s stems 7 Compa? ,"esa"io : installed in t!is Lab3 9!ei" confi+u"ations a"e as folloAs : ,"ocesso" @AM Ca"d Dis< Mouse : : : : AMD At!elon B &3./ GC# )5. MB *= GB Optical Mouse ,"esent

NetAo"< Inte"face ca"d :

'o%t9are
All s stems a"e confi+u"ed in DUA* .11/ mode i3e31 Students can boot f"om DindoAs E, o" Linu6 as pe" t!ei" lab "e?ui"ement3 9!is is $e" useful fo" students because t!e a"e familia" Ait! diffe"ent Ope"atin+ S stems so t!at t!e can e6ecute t!ei" p"o+"ams in diffe"ent p"o+"ammin+ en$i"onments3

Eac! student !as a sepa"ate lo+in fo" database access 1racle :i client $e"sion is installed in all s stems3 On t!e se"$e"1 account fo" eac! student !as been c"eated3 9!is is $e" useful because students can sa$e t!ei" Ao"< 7scena"iosF1 pl / s?l p"o+"ams1 data "elated p"o'ects1 etc: in t!ei" oAn accounts3 Eac! student Ao"< is safe and secu"e f"om ot!e" students3

K.Ravi

DBMS Lab Manual Latest 9ec!nolo+ies li<e D1/ NE/ and 65EE a"e installed in some s stems3 Befo"e submittin+ t!ei" final p"o'ect1 t!e can sta"t doin+ mini p"o'ect f"om )nd ea" onAa"ds3

(A'( !(acro Assembler$ is installed in all t!e s stems Students can e6ecute t!ei" assembl lan+ua+e p"o+"ams usin+ MASM3 MASM is $e" useful students because A!en t!e e6ecute t!ei" p"o+"ams t!e can see contents of #rocessor Registers and !oA each instr&ction is bein+ e6ecuted in t!e C#U3

@ational @ose SoftAa"e is installed in some s stems Usin+ t!is softAa"e1 students can depict UML dia+"ams of t!ei" p"o'ects3 'o%t9ares installe3 0 C1 CGG1 8D2&351 MASM1 OHHICE>E,1 8)EE and DO9 NE91 @ational @ose3

')stems are pro4i3e3 %or st&3ents in the 101 ratio" ')stems are assigne3 n&mbers an3 same s)stem is allotte3 %or st&3ents 9hen the) 3o the lab"

K.Ravi

DBMS Lab Manual

'/ANDARD 1#ERA/ING #R1CEDURE '1#


a: E6planation on toda Fs e6pe"iment b t!e conce"ned facult usin+ OC,/,,9 co$e"in+ t!e folloAin+ aspects: )5 mins3 &: ): (: *: &: ): Name of t!e e6pe"iment/Aim SoftAa"e/Ca"dAa"e "e?ui"ed Al+o"it!m 9est Data %alid data sets Limitin+ $alue sets (: In$alid data sets b: D"itin+ of sou"ce p"o+"am b t!e students min3 c: Compilin+ and e6ecution of t!e p"o+"am )5

&== mins3 ;riting o% the e<periment in the 1bser4ation .oo=: 9!e students Aill A"ite t!e toda Fs e6pe"iment in t!e Obse"$ation boo< as pe" t!e folloAin+ fo"mat: a: b: c: d: e: a3 b3 c3 f: K.Ravi Name of t!e e6pe"iment/Aim SoftAa"e/Ca"dAa"e "e?ui"ed Al+o"it!m Sou"ce ,"o+"am 9est Data %alid data sets Limitin+ $alue sets In$alid data sets @esults fo" diffe"ent data sets 6

DBMS Lab Manual +: !: i: %i$a>%oc 0uestions and AnsAe"s E""o"s obse"$ed 7if an : du"in+ compilation/e6ecution Si+natu"e of t!e Hacult

K.Ravi

DBMS Lab Manual

G&i3elines to 't&3ents

E?uipment in t!e lab fo" t!e use of student communit 3 Students need to maintain a p"ope" deco"um in t!e compute" lab3 Students must use t!e e?uipment Ait! ca"e3 An dama+e is caused is punis!able3 Students a"e "e?ui"ed to ca"" t!ei" obse"$ation / p"o+"ams boo< Ait! completed e6e"cises A!ile ente"in+ t!e lab3 Students a"e supposed to occup t!e mac!ines allotted to t!em and a"e not supposed to tal< o" ma<e noise in t!e lab3 9!e allocation is put up on t!e lab notice boa"d3 Lab can be used in f"ee time / lunc! !ou"s b t!e students A!o need to use t!e s stems s!ould ta<e p"io" pe"mission f"om t!e lab in> c!a"+e3 Lab "eco"ds need to be submitted on o" befo"e date of submission3 Students a"e not supposed to use flopp dis<s

K.Ravi

DBMS Lab Manual 2o9 to ;rite an3 e<ec&te s>l, pl?s>l comman3s?programs0 &:3 Open ou" o"acle application b t!e folloAin+ na$i+ation Sta"t>Iall p"o+"ams>Io"acle o"a!ome3>Iapplication de$elopment>Is?l3 ):3 Jou Aill be as<ed fo" use" name1 pass Ao"d and !ost st"in+ Jou !a$e to ente" use" name1 pass Ao"d and !ost st"in+ as +i$en b t!e administ"ato"3 It Aill be diffe"ent f"om one use" to anot!e" use"3 (:3 Upon successful lo+in ou Aill +et S0L p"ompt 7S0LI:3 In tAo Aa s ou can A"ite ou" p"o+"ams: a:3 di"ectl at S0L p"ompt b:3 o" in s?l edito"3 If ou t pe ou" p"o+"ams at s?l p"ompt t!en sc"een Aill loo< li<e folloA: S0LI SELEC9 ename1empno1 ) sal f"om ( empK A!e"e ) and ( a"e t!e line numbe"s and "est is t!e command /p"o+"amLL to e6ecute abo$e p"o+"am/command ou !a$e to p"ess M/F t!en ente"3 Ce"e editin+ t!e p"o+"am is someA!at difficultK if ou Aant to edit t!e p"e$ious command t!en ou !a$e to open s?l edito" 7b default it displa s t!e s?l buffe" contents:3 B +i$in+ MedF at s?l p"ompt37t!is is A!at I mentioned as a second met!od to t pe/ente" t!e p"o+"am:3 in t!e s?l edito" ou can do all t!e fo"mattin+/editin+/file ope"ations di"ectl b selectin+ menu options p"o$ided b it3 9o e6ecute t!e p"o+"am A!ic! sa$edK do t!e folloAin+ S0LI N p"o+"amname3s?l O" S0LI @un p"o+"amname3s?l 9!en p"ess MOF <e and ente"3 9!is !oA Ae can A"ite1 edit and e6ecute t!e s?l command and p"o+"ams3 AlAa s ou !a$e to sa$e ou" p"o+"ams in ou" oAn lo+ins3

K.Ravi

DBMS Lab Manual

*ist o% *ab E<ercises ')llab&s #rograms !6N/U$ '" No


1

Name o% the program


Database 'chema %or a c&stomer@sale scenario Custome"7C&st i3 0 integer, custPname: st"in+: Item7itemAi30 integer, itemPname: st"in+1 p"ice: inte+e": Sale7billAno0 integer, billPdata: date1 c&stAi30 integer, itemAi30 integer1 ?t Psold: inte+e": Ho" t!e abo$e sc!ema1 pe"fo"m t!e folloAin+Q a) C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List all t!e bills fo" t!e cu""ent date Ait! t!e custome" names and item numbe"s d: List t!e total Bill details Ait! t!e ?uantit sold1 p"ice of t!e item and t!e final amount e: List t!e details of t!e custome" A!o !a$e bou+!t a p"oduct A!ic! !as a p"iceI)== f: Gi$e a count of !oA man eac! custome" p"oducts !a$e been bou+!t b a custome" !a$in+

+: Gi$e a list of p"oducts bou+!t b custPid as 5

!: List t!e item details A!ic! a"e sold as of toda i: C"eate a $ieA A!ic! lists out t!e billPno1 billPdate1 custPid1 itemPid1 p"ice1 ?t Psold1 amount C"eate a $ieA A!ic! lists t!e dail sales date Aise fo" t!e last one Aee< 5 Database 'chema %or a 't&3ent *ibrar) scenario Student7't&3Ano 0 integer, StudPname: st"in+: Membe"s!ip7(emAno0 integer1 't&3Ano0 integer: Boo<7boo=Ano0 integer1 boo<Pname:st"in+1 aut!o": st"in+: IssP"ec!issAno0integer1 issPdate: date1 (emAno0 integer1 boo=Ano0 integer: K.Ravi 10

DBMS Lab Manual

Ho" t!e abo$e sc!ema1 pe"fo"m t!e folloAin+Q a: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List all t!e student names Ait! t!ei" membe"s!ip numbe"s d: List all t!e issues fo" t!e cu""ent date Ait! student and Boo< names e: List t!e details of students A!o bo""oAed boo< A!ose aut!o" is C8DA9E f: Gi$e a count of !oA man boo<s !a$e been bou+!t b eac! student +: Gi$e a list of boo<s ta<en b student Ait! studPno as 5 !: List t!e boo< details A!ic! a"e issued as of toda i: C"eate a $ieA A!ic! lists out t!e issPno1 iss Pdate1 studPname1 boo< name ': C"eate a $ieA A!ic! lists t!e dail issues>date Aise fo" t!e last one Aee< B Database 'chema %or a Emplo)ee@pa) scenario emplo ee7empAi3 0 integer1 empPname: st"in+: depa"tment73eptAi30 integer1 deptPname:st"in+: pa details7empAi3 0 integer1 3eptAi30 integer1 basic: inte+e"1 deductions: inte+e"1 additions: inte+e"1 DO8: date: pa "oll!empAi3 0 integer1 pa Pdate: date: Ho" t!e abo$e sc!ema1 pe"fo"m t!e folloAin+Q a: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List t!e emplo ee details depa"tment Aise d: List all t!e emplo ee names A!o 'oined afte" pa"ticula" date e: List t!e details of emplo ees A!ose basic sala" is betAeen &=1=== and )=1=== f: Gi$e a count of !oA man emplo ees a"e Ao"<in+ in eac! depa"tment +: Gi$e a names of t!e emplo ees A!ose netsala" I&=1=== !: List t!e details fo" an emplo eePidR5 i: C"eate a $ieA A!ic! lists out t!e empPname1 depa"tment1 basic1 dedeuctions1 netsala" K.Ravi 11

DBMS Lab Manual ': C"eate a $ieA A!ic! lists t!e empPname and !is netsala" C Database 'chema %or a 8i3eo *ibrar) scenario Custome"7custPno: inte+e"1custPname: st"in+: Membe"s!ip7(emAno0 integer1 c&stAno0 integer: Cassette7cassAno0integer1 cassPname:st"in+1 Lan+ua+e: St"in+: IssP"ec!issAno0 integer1 issPdate: date1 memAno0 integer1 cassAno0 integer: Ho" t!e abo$e sc!ema1 pe"fo"m t!e folloAin+Q a: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List all t!e custome" names Ait! t!ei" membe"s!ip numbe"s d: List all t!e issues fo" t!e cu""ent date Ait! t!e custome" names and cassette names e: List t!e details of t!e custome" A!o !as bo""oAed t!e cassette A!ose title is S 9!e Le+endT f: Gi$e a count of !oA man cassettes !a$e been bo""oAed b eac! custome" +: Gi$e a list of boo< A!ic! !as been ta<en b t!e student Ait! memPno as 5 !: List t!e cassettes issues fo" toda i: C"eate a $ieA A!ic! lists outs t!e issPno1 issPdate1 custPname1 cassPname ': C"eate a $ieA A!ic! lists issues>date Aise fo" t!e last one Aee< 5 Database 'chema %or a st&3ent@*ab scenario Student7st&3Ano0 integer1 studPname: st"in+1 class0 string: Class7class0 string, 3escrip0 string: Lab7machAno0 integer1 LabPno: inte+e"1 desc"iption: St"in+: Allotment7't&3Ano0 Integer, machAno0 integer, 3a)o% 9ee=0 string$ Ho" t!e abo$e sc!ema1 pe"fo"m t!e folloAin+Q a: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List all t!e mac!ine allotments Ait! t!e student names1 lab and mac!ine numbe"s d: List t!e total numbe" of lab allotments da Aise e: Gi$e a count of !oA man mac!ines !a$e been allocated K.Ravi 12

DBMS Lab Manual to t!e MCSI9F class f: Gi$e a mac!ine allotment etails of t!e studPno 5 Ait! !is pe"sonal and class details g) Count fo" !oA man mac!ines !a$e been allocatedin *abAno 1 fo" t!e da of t!e Aee< as SMonda T !: CoA man students class Aise !a$e allocated mac!ines in t!e labs i: C"eate a $ieA A!ic! lists out t!e studPno1 studPname1 mac!Pno1 labPno1 da ofAee< j) C"eate a $ieA A!ic! lists t!e mac!ine allotment details fo" S9!u"sda T3 D"ite a p"o+"am to find la"+est numbe" f"om t!e +i$en t!"ee numbe"s3 Simple p"o+"ams usin+ loop1 A!ile and fo" ite"ati$e cont"ol statement3 D"ite a p"o+"am to c!ec< A!et!e" t!e +i$en numbe" is A"mst"on+ o" not D"ite a p"o+"am to +ene"ate all p"ime numbe"s beloA &==3 D"ite a p"o+"am to demonst"ate t!e GO9O statement3 D"ite a p"o+"am to demonst"ate Ut pe and U"oAt pe att"ibutes D"ite a p"o+"am to demonst"ate p"edefined e6ceptions D"ite a p"o+"am to demonst"ate use" defined e6ceptions C"eate a cu"so"1 A!ic! displa s all emplo ee numbe"s and names f"om t!e EM, table3 C"eate a cu"so"1 A!ic! update t!e sala"ies of all emplo ees as pe" t!e +i$en data3 C"eate a cu"so"1 A!ic! displa s names of emplo ees !a$in+ sala" I 5====3 C"eate a p"ocedu"e to find "e$e"se of a +i$en numbe" C"eate a p"ocedu"e to update t!e sala"ies of all emplo ees as pe" t!e +i$en data C"eate a p"ocedu"e to demonst"ate IN1 OU9 and INOU9 pa"amete"s C"eate a function to c!ec< A!et!e" +i$en st"in+ is palind"ome o" not3 C"eate a function to find sum of sala"ies of all emplo ees Ao"<in+ in depa"t numbe" &=3 C"eate a t"i++e" befo"e/afte" update on emplo ee table fo" eac! "oA/statement3 C"eate a t"i++e" befo"e/afte" delete on emplo ee table fo" eac! "oA/statement3 C"eate a t"i++e" befo"e/afte" inse"t on emplo ee table fo" eac!

, D : 10 11 15 1B 1C 15 1 1, 1D 1: 50 51 55 5B 5C

K.Ravi

13

DBMS Lab Manual "oA/statement3 C"eate a Ho"m to displa emplo ee details usin+ S0L C"eate a @epo"t to +ene"ate all emplo ee annual sala"iesL3

55 5

A33itional #rograms '" No


1 5 B C

Name o% the #rogram


C"eate a fo"m usin+ Ho"ms .i to displa Emplo ee table data3 C"eate a Maste"/details "elations!ip fo"m A!ic! pe"fo"m Add NeA1 Sea"c!1 Delete1 Sa$e and Update on t!e "eco"ds Gene"ate a "epo"t to calculate emplo eeFs sala"ies depa"tment Aise f"om emplo ee table3 C"eate a @epo"t to +ene"ate t!e details of emplo ee table includin+ sum and a$e"a+e sala"ies depa"tment Aise3

K.Ravi

14

DBMS Lab Manual

.ac=gro&n3 /heor)
O"acle Ao"<+"oup o" se"$e" is t!e la"+est sellin+ @DBMS p"oduct3it is estimated t!at t!e combined sales of bot! t!ese o"acle database p"oduct account fo" a"oud 4=U of t!e @DBMSs stems sold Ao"ldAide3 9!ese p"oducts a"e constantl unde"+oin+ c!an+e and e$ol$in+3 9!e natu"al lan+ua+e of t!is @DBMS p"oduct is ANSI S0L1,L/S0L a supe"set of ANSI S0L3o"acle 4i and ;i also unde" stand S0L83 O"acle co"p !as also inco"po"ated a full>fled+ed 'a$a $i"tual mac!ine into its database en+ine3since bot! e6ecutable s!a"e t!e same memo" space t!e 8%M can communicate Dit! t!e database en+ine Ait! ease and !as di"ect access to o"acle tables and t!ei" data3 S0L is st"uctu"e ?ue" lan+ua+e3S0L contains diffe"ent data t pes t!ose a"e &3 c!a"7si#e: )3 $a"c!a")7si#e: (3 date *3 numbe"7p1s: 53 lon+ .3 "aA/lon+ "aA

Di%%erent t)pes o% comman3s in 'E*0


A). DD* comman3s0 @ 9o c"eate a database ob'ects B). D(* comman3s0 @ 9o manipulate data of a database ob'ects C). DE* comman30 @ 9o "et"ie$e t!e data f"om a database3 D). DC*?D/* comman3s0 @ 9o cont"ol t!e data of a databaseL

DD* comman3s0
1" /he Create /able Comman30 @ it defines eac! column of t!e table uni?uel 3 Eac! column !as minimum of t!"ee att"ibutes1 a name 1 data t pe and si#e3 ')nta<0 Create table Vtable Vdatat peIVsi#eI::K nameI 7Vcol&I Vdatat peI7Vsi#eI:1Vcol)I

E<0 c"eate table emp7empno numbe"7*: p"ima" <e 1 ename c!a"7&=::K

K.Ravi

15

DBMS Lab Manual 5" (o3i%)ing the str&ct&re o% tables" a:add neA columns ')nta<0 Alter table VtablenameI colIdatat pe7si#e::K E<0 alte" table emp add7sal numbe"7/1)::K B" Dropping a col&mn %rom a table" ')nta<0 Alte" table VtablenameI d"op column VcolIK E<0 alte" table emp d"op column salK C" (o3i%)ing e<isting col&mns" ')nta<0 Alte" table VtablenameI modif 7VcolIVneAdatat peI7VneAsi#eI::K E<0 alte" table emp modif 7ename $a"c!a")7&5::K 5" Renaming the tables ')nta<0 Rename VoldtableI to VneA tableIK E<0 "ename emp to emp&K " tr&ncating the tables" ')nta<0 /r&ncate table VtablenameIK E<0 t"unc table emp&K add7VneA colIVdatat pe7si#e:1VneA

K.Ravi

16

DBMS Lab Manual ," Destro)ing tables" ')nta<0 Drop table VtablenameIK E<0 d"op table empK

D(* comman3s0
D" Inserting Data into /ables0 @ once a table is c"eated t!e most natu"al t!in+ to do is load t!is table Ait! data to be manipulated late"3 ')nta<0 inse"t into VtablenameI 7Vcol&I1Vcol)I: $alues7Ve6pI1Ve6pI:K :" Delete operations" a$ "emo$e all "oAs ')nta<0 delete f"om VtablenameIK b$ "emo$al of a specified "oA/s ')nta<0 delete f"om VtablenameI A!e"e VconditionIK 10" Up3ating the contents o% a table" a$ updatin+ all "oAs ')nta<0 Update VtablenameI set VcolIRVe6pI1VcolIRVe6pIK b$ updatin+ seleted "eco"ds3 S nta6: Update VtablenameI set A!e"e VconditionIK

VcolIRVe6pI1VcolIRVe6pI

11" /)pes o% 3ata constrains" a$ not null const"aint at column le$el3 ')nta<0 VcolIVdatat peI7si#e:not null b$ uni?ue const"aint ')nta<0 K.Ravi 17

DBMS Lab Manual Uni?ue const"aint at column le$el3 VcolIVdatat peI7si#e:uni?ueK c$ uni?ue const"aint at table le$el: ')nta<0 C"eate table tablename7colRfo"mat1colRfo"mat1uni?ue7Vcol&I1Vcol)I:K 3$ p"ima" <e const"aint at column le$el ')nta<0 VcolIVdatat peI7si#e:p"ima" <e K e$ p"ima" <e const"aint at table le$el3 ')nta<0 C"eate table tablename7colRfo"mat1colRfo"mat p"ima" <e 7col&I1Vcol)I:K %$ fo"ei+n <e const"aint at column le$el3 ')nta<0 VcolIVdatat peI7si#eI: "efe"ences VtablenameIWVcolIXK g$ fo"ei+n <e const"aint at table le$el ')nta<0 fo"ei+n <e 7VcolIW1VcolIX:"efe"ences VtablenameIW7VcolI1VcolI: h$ c!ec< const"aint c!ec< const"aint const"aint at column le$el3 ')nta<0 VcolIVdatat peI7si#e: c!ec<7Vlo+ical e6p"essionI: i$ c!ec< const"aint const"aint at table le$el3 ')nta<0 c!ec<7Vlo+ical e6p"essionI:

K.Ravi

18

DBMS Lab Manual

DE* Comman3s0
15" 8ie9ing 3ata in the tables: > once data !as been inse"ted into a table1 t!e ne6t most lo+ical ope"ation Aould be to $ieA A!at !as been inse"ted3 a$ all "oAs and all columns ')nta<0 Select VcolI to Vcol nI f"om tablenameK Select Y f"om tablenameK 1B" Filtering table 3ata: > A!ile $ieAin+ data f"om a table1 it is "a"e t!at all t!e data f"om table Aill be "e?ui"ed eac! time3 Cence1 s?l must +i$e us a met!od of filte"in+ out data t!at is not "e?ui"ed data3 a$ Selected columns and all "oAs: ')nta<0 select Vcol&I1Vcol)I f"om VtablenameIK b$ selected "oAs and all columns: ')nta<0 select Y f"om VtablenameI A!e"e VconditionIK c$ selected columns and selected "oAs ')nta<0 select Vcol&I1Vcol)I f"om VtablenameI A!e"eVconditionIK 1C" 'orting 3ata in a table" ')nta<0 Select Y f"om VtablenameI o"de" b Vcol&I1Vcol)I VWso"to"de"XIK

DC* comman3s0
O"acle p"o$ides e6tensi$e featu"e in o"de" to safe+ua"d info"mation sto"ed in its tables f"om unaut!o"aised $ieAin+ and dama+e39!e "i+!ts t!at alloA t!e use" of some o" all o"acle "esou"ces on t!e se"$e" a"e called p"i$ile+es3 a$ G"ant p"i$ile+es usin+ t!e G@AN9 statement 9!e +"ant statement p"o$ides $a"ious t pes of access to database ob'ects suc! as tables1$ieAs and se?uences and so on3

K.Ravi

19

DBMS Lab Manual ')nta<0 G@AN9 Vob'ect p"i$ile+esI ON Vob'ectnameI 9OVuse"nameI WDI9C G@AN9 O,9IONXK b$ @eo<e pe"missions usin+ t!e @E%O2E statement: 9!e @E%O2E statement is used to den t!e G"ant +i$en on an ob'ect3 ')nta<0 @E%O2EVob'ect p"i$ile+eI ON H@OMVuse" nameIK

K.Ravi

20

DBMS Lab Manual

'ol&tions %or programs !6N/U ')llab&s$ 1" Database 'chema %or a c&stomer@sale scenario
Custome"7C&st i3 0 integer, custPname: st"in+: Item7itemAi30 integer1 itemPname: st"in+1 p"ice: inte+e": Sale7billAno0 integer1 billPdata: date1 c&stAi30 integer, integer1 ?t Psold: inte+e":

itemAi30

Ho" t!e abo$e sc!ema1 pe"fo"m t!e folloAin+Q a: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List all t!e bills fo" t!e cu""ent date Ait! t!e custome" names and item numbe"s d: List t!e total Bill details Ait! t!e ?uantit sold1 p"ice of t!e item and t!e final amount e: List t!e details of t!e custome" A!o !a$e bou+!t a p"oduct A!ic! !as a p"iceI)== f: Gi$e a count of !oA man p"oducts !a$e been bou+!t b eac! custome" +: Gi$e a list of p"oducts bou+!t b a custome" !a$in+ custPid as 5 !: List t!e item details A!ic! a"e sold as of toda i: C"eate a $ieA A!ic! lists out t!e billPno1 billPdate1 custPid1 itemPid1 p"ice1 ?t Psold1 amount j) C"eate a $ieA A!ic! lists t!e dail sales date Aise fo" t!e last one Aee<

K.Ravi

21

DBMS Lab Manual

Aim: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints and Inse"t
a"ound &= "eco"ds in eac! of t!e tables

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< SoftAa"e : : : : AMD At!elon B &3./ GC# )5. MB *= GB O@ACLE

S0LI c"eate table custome"& 7custPid numbe"75: p"ima" <e 1 custPname $a"c!a")7&5::K 1&tp&t0 9able c"eated3 S0LI desc custome"&K 1&tp&t0 Name NullZ 9 pe >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>> >>>>>>>>>>>>>>>> CUS9PID NO9 NULL NUMBE@75: CUS9PNAME %A@CCA@)7&5: 8ali3 /est Data b$ S0LI inse"t into custome"& $alues7[custid1\[custname\:K S0LI select Y f"om custome"&K 1&tp&t0 CUS9PID CUS9PNAME >>>>>>>>>> >>>>>>>>>>>>>>> &== "amu &=& <amal &=) "a'u &=( "a'u sunda"am &=* laA"ence S0LI c"eate table item7itemPid numbe"7*: p"ima" <e 1 itemPname $a"c!a")7&5:1p"ice numbe"7.1)::K S0LI dsec item 1&tp&t0 Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL

K.Ravi

22

DBMS Lab Manual CustPid NO9 NULL NUMBE@7*: ItemPname %A@CCA@)7&5: ,@ICE NUMBE@7.1): S0LIinse"t into item $alues7[itemPid1F[itemPnameF1[p"ice:K S0LI select Y f"om itemK 1&tp&t0 I9EMPID I9EMPNAME ,@ICE LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 )((* +ee"a .3)5 *5() co"n soup (*3.5 )&)* la s c!ips )= *5(& setAet ;;3;; )(&; du"acell *535 S0LIc"eate table sale7billPno numbe"75: p"ima" <e 1billPdate date1 custPid numbe"75: "efe"ences custome"7custPid:1 itemPid numbe"7*: "efe"ences item7itemPid:1?t Psold numbe"7*::K 1&t p&t: 9able C"eated3 S0LIdsec sale 1&tp&t0 Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 BILLPNO NO9 NULL NUMBE@7*: BILLPDA9E DA9E CUS9PID NUMBE@75: I9EMPID NUMBE@7*: 09JPSOLD NUMBE@7*: S0LIinse"t into Sale $alues7[billPno1 F[billPdateF1 [custPid1 [itemPid1 [?t Psold:K S0LIselect Y f"om saleK 1&tp&t0 BILLPNO BILLPDA9E CUS9PID I9EMPID 09JPSOLD LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL333 &*5= =*>8AN>=. &== )&)* ) &*5& =*>8AN>=. &=& )(&; & &*5) =*>8AN>=. &=( *5(& ) &*5( =*>8AN>=. &=) )((* ( K.Ravi 23

DBMS Lab Manual &*5* =*>8AN>=. &=* *5() (

c$ List all t!e bills fo" t!e cu""ent date Ait! t!e custome" names and item numbe"s S0LI select c3custname1 i3itemid1 s3billno f"om custome" c1 item I1 sale s A!e"e c3custidRs3custid and s3billdateRtoPc!a"7s sdate:K CUS9NAME >>>>>>>>>>>>> 8o!n I9EMID >>>>>>>>> 5==& BILLNO >>>>>>>>> (()

3$ List t!e total Bill details Ait! t!e ?uantit sold1 p"ice of t!e item and t!e final amount S0LI select i3p"ice1 s3?t 17i3p"iceYs3?t : total f"om item I1 sale s A!e"e i3itemidRs3itemidK ,@ICE >>>>>>> &)= )= 5 &= (5= 09J >>>>> ) ( ) & * 9O9AL >>>>>>>> )*= .= &= &= &*==

e$ List t!e details of t!e custome" A!o !a$e bou+!t a p"oduct A!ic! !as a p"iceI)== S0LI select c3custid1 c3custname f"om custome" c1 sale s1 item i A!e"e i3p"iceI)== and c3custidRs3custid and i3itemidRs3itemidK CUS9ID >>>>>>>>> * CUS9NAME >>>>>>>>>>>>>> duff

%$ Gi$e a count of !oA man p"oducts !a$e been bou+!t b eac! custome" S0LI select custid1 count7itemid: f"om sale +"oup b custidK CUS9ID >>>>>>>>>> & K.Ravi COUN97I9EMID: >>>>>>>>>>>>>>>>>>>>> ) 24

DBMS Lab Manual ( * 5 & & & g$ Gi$e a list of p"oducts bou+!t b a custome" !a$in+ custPid as 5 S0LI select i3itemname f"om item i1 sale s A!e"e s3custidR5 and i3itemid>s3itemidK I9EMNAME >>>>>>>>>>>>>> ,ens

h$ List t!e item details A!ic! a"e sold as of toda S0LI select i3itemid1 i3itemname f"om item I1 sale s A!e"e i3itemidRs3itemid and s3billdateRtoPc!a"7s sdate:K I9EMID >>>>>>>>> &)(* I9EMNAME >>>>>>>>>>>>> pencil

i$ C"eate a $ieA A!ic! lists out t!e billPno1 billPdate1 custPid1 itemPid1 p"ice1 ?t Psold1 amount S0LIc"eate $ieA cust as 7select s3billno1 s3billdate1 c3custid1 i3 iitemid1 i3p"ice1 s3?t f"om custome" c1sale s item I A!e"e c3custidRs3custid and i3iemidRs3itemid:K $ieA c"eated3 S0LIselect Y f"om custK BILLNO BILLDA9E CUS9ID I9EMID ,@ICE 09J LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL (*() &)>8AN>=. ( ()** &)= ) **)* )=>HEB>=. & (*5. )= ( (() &(>MA@>=. & &)(* 5 ) )(*( &=>MA@ 5 5==& &= & &((& &&>MA@>=. * /.//. (5= * G$ C"eate a $ieA A!ic! lists t!e dail sales date Aise fo" t!e last one Aee< K.Ravi 25

DBMS Lab Manual

8i4a@8oce0
0&3 D!at is S0LZ Ans: St"uctu"ed 0ue" Lan+ua+e 2. What is database? A database is a lo+icall co!e"ent collection of data Ait! some in!e"ent

meanin+1 "ep"esentin+ some aspect of "eal Ao"ld and A!ic! is desi+ned1 built and populated Ait! data fo" a specific pu"pose3 3. What is DBMS? It is a collection of p"o+"ams t!at enables use" to c"eate and maintain a database3 In ot!e" Ao"ds it is +ene"al>pu"pose softAa"e t!at p"o$ides t!e use"s Ait! t!e p"ocesses of defining1 constructing and manipulating t!e database fo" $a"ious applications3 4. What is a Database system? 9!e database and DBMS softAa"e to+et!e" is called as Database s stem3 5. ". d!antages of DBMS? @edundanc is cont"olled3 Unaut!o"ised access is "est"icted3 ,"o$idin+ multiple use" inte"faces3 Enfo"cin+ inte+"it const"aints3 ,"o$idin+ bac<up and "eco$e" 3 Disad!antage in #ile $rocessing System? Data "edundanc [ inconsistenc 3 Difficult in accessin+ data3 Data isolation3 Data inte+"it 3 Concu""ent access is not possible3 Secu"it ,"oblems3

K.Ravi

26

DBMS Lab Manual

5" Database 'chema %or a 't&3ent *ibrar) scenario


Student7't&3Ano 0 integer, StudPname: st"in+: Membe"s!ip7(emAno0 integer1 't&3Ano0 integer: Boo<7boo=Ano0 integer1 boo<Pname:st"in+1 aut!o": st"in+: IssP"ec!issAno0integer1 issPdate: date1 (emAno0 integer1 boo=Ano0 integer: For the abo4e schema, per%orm the %ollo9ingH a$ C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b$ Inse"t a"ound &= "eco"ds in eac! of t!e tables c$ List all t!e student names Ait! t!ei" membe"s!ip numbe"s 3$ List all t!e issues fo" t!e cu""ent date Ait! student and Boo< names e$ List t!e details of students A!o bo""oAed boo< A!ose aut!o" is C8DA9E %$ Gi$e a count of !oA man boo<s !a$e been bou+!t b eac! student g$ Gi$e a list of boo<s ta<en b student Ait! studPno as 5 h$ List t!e boo< details A!ic! a"e issued as of toda i$ C"eate a $ieA A!ic! lists out t!e issPno1 iss Pdate1 studPname1 boo< name G$ C"eate a $ieA A!ic! lists t!e dail issues>date Aise fo" t!e last one Aee<

K.Ravi

27

DBMS Lab Manual AI(0 C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints Inse"t a"ound &= "eco"ds in eac! of t!e tables

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e

O"acle

S0LIc"eate table student7studPno numbe"75: p"ima" <e 1studPname $a"c!a")7&5::K S0LIdesc studentK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 S9UDPNO NO9 NULL NUMBE@75: S9UDPNAME %A@CAC@)7&5: 8ali3 /est Data0 S0LIinse"t into student $alues7[studPno1F[studPnameF:K S0LIselect Y f"om studentK S9UDPNO S9UDPNAME 33333333333333333333333333333333333333333333333333333333333333333333 5=4 5&( 5&4 5)* 5(* CA@ISC BALA8I @A2ESC ,A%AN 8OJCE

S0LIc"eate table membe"s!ip7memPno numbe"75: p"ima" <e 1studPno numbe"75: "efe"ences student7stud:no::K S0LIdsec membe"s!ipK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL3 MEMPNO NO9 NULL NUMBE@75: S9UDPNO NUMBE@75:

K.Ravi

28

DBMS Lab Manual S0LIinse"t into membe"s!ip $alues7[memPno1[studPno:K Ente" $alue fo" memPno:5**= Ente" $alue fo" studPno:5&= old &:inse"t into membe"s!ip $alues7[memPno1[studPno: neA &:inse"t into membe"s!ip $alues75**=15&=: inse"t into membe"s!ip $alues75**=15&=: Y Errors 1bser4e30 E@@O@ at line &: O@A>=));&:inte+"it const"aint7CA@ISC3SJSPC==)/)*:$iolated>p"ima" <e not found S0LIselect Y f"om membe"s!ipK MEMPNO S9UDPNO LLLLLLLLLLLLLLLLLLLLLLLLLLL33 5**= 5&( 5**& 5=4 5**) 5&4 5**( 5(* 5*** 5)* S0LIc"eate table boo<7boo<Pno numbe"75: p"ima" <e 1boo<Pname $a"c!a")7)=:1aut!o" $a"c!a")7)::K S0LIdesc boo<K Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 BOO2PNO NO9 NULL NUMBE@75: BOO2PNAME %A@CCA@)7)=: AU9CO@ %A@CCA@)7)=: S0LIinse"t into boo< $alues7[boo<Pno1F[boo<PnameF1F[aut!o"F:K S0LIselect Y f"om boo<K BOO2PNO BOO2PNAME AU9CO@ LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 ;&)( DBMS @ama 2"is!na )(*) 8A%A @obett Ail<ins *5)( Hea"less tales Alf"ed 4/)( m ambition Ca"is! /4)& Ca"" ,otte" 82 @oAlin+

K.Ravi

29

DBMS Lab Manual S0LIc"eate table lssP"ec7issPno numbe" p"ima" <e 1issPdate date1memPno numbe"75: "efe"ences membe"s!ip7memPno:1boo<Pno numbe"75: "efe"ences boo<7boo<Pno::K S0LIdesc issP"ecK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL ISSPNO NO9 NULL NUMBE@ ISSPDA9E DA9E MEMPNO NUMBE@75: BOO2PNO NUMBE@75: S0LIselect Y f"om issP"ecK ISSPNO ISSPDA9E MEMPNO BOO2PNO LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL *( =5>8AN>=. 5**( *5)( 4& )4>DEC>=5 5**& 4/)( )) =4>DEC>=5 5**= /4)& 5( =/>8AN>=. 5**) ;&)( (5 =.>8AN>=. 5*** )(*) c$ List all t!e student names Ait! t!ei" membe"s!ip numbe"s S0LI select s3studname1 m3memno f"om student s1 membe"s!ip m A!e"e m3studnoRs3studnoK S9UDNAME MEMNO >>>>>>>>>>>>>>>>>>>>> ab!i'eet &==& a"un &==) a"$ind &==( as!is! &==* as!Ain &==5 3$ List all t!e issues fo" t!e cu""ent date Ait! student and Boo< names S0LI select i3issno1 s3studname1 b3boo<name f"om issP"ec I1 membe"s!ip m1 student s1 boo< b ) A!e"e i3memnoRm3memno and m3studnoRs3studno and i3issdateRtoPc!a"7s sdate:K ISSNO >>>>>>> K.Ravi S9UDNAME BOO2NAME >>>>>>>>>>>> >>>>>>>>>>>>>>> 30

DBMS Lab Manual &( a"$ind ,[S

e$ List t!e details of students A!o bo""oAed boo< A!ose aut!o" is C8DA9E S0LI select Y f"om student A!e"e studno in7select studno f"om membe"s!ip A!e"e memno in ) 7select memno f"om issP"ec A!e"e boo<no in7select boo<no f"om boo< A!e"e aut!o"RFC8DA9EF:::K S9UDNO >>>>>>>>>> 5=5 S9UDNAME >>>>>>>>>>>>> as!Ain

%$ Gi$e a count of !oA man boo<s !a$e been bou+!t b eac! student S0LI select s3studno1 count7i3boo<no: f"om student s3membe"s!ip m1 boo< b1 ) issP"ec I A!e"e s3studnoRm3studno and b3boo<noRi3boo<no +"oup b s3studnoK S9UDNO >>>>>>>>>> 5=& 5=) 5=( 5=* 5=5 COUN97I3BOO2NO: >>>>>>>>>>>>>>>>>>>>>>> 5 5 5 5 5

g$ Gi$e a list of boo<s ta<en b student Ait! studPno as 5 S0LI select boo<name f"om boo< A!e"e boo<no in 7select boo<no f"om issP"ec A!e"e ) memno in7select memno f"om membe"s!ip A!e"e ( studno in7select studno f"om student A!e"e studnoR5:::K BOO2NAME >>>>>>>>>>>>> N9 h$ List t!e boo< details A!ic! a"e issued as of toda S0LI delete f"om boo< A!e"e boo<no in7select boo<no f"om issP"ec A!e"e issdateRtoPc!a"7s sdate::K

K.Ravi

31

DBMS Lab Manual delete f"om boo< A!e"e boo<no in 7select boo<no f"om issP"ec A!e"e issdateRtoPc!a"7s sdate:: Errors 1bser4e30 E@@O@ at line &: O@A>=));): inte+"it const"aint 7SCO993SJSPC==4*=: $iolated - c!ild "eco"d found i$ C"eate a $ieA A!ic! lists out t!e issPno1 iss Pdate1 studPname1 boo< name

G$ C"eate a $ieA A!ic! lists t!e dail issues>date Aise fo" t!e last one Aee<

8i4a@8ice0 %. Describe the three le!els of data abstraction? 9!e a"e t!"ee le$els of abst"action: $hysical le!el& 9!e loAest le$el of abst"action desc"ibes !oA data a"e sto"ed3 'ogical le!el& 9!e ne6t !i+!e" le$el of abst"action1 desc"ibes A!at data a"e sto"ed in database and A!at "elations!ip amon+ t!ose data3 (ie) le!el& 9!e !i+!est le$el of abst"action desc"ibes onl pa"t of enti"e database3 2. Define the *integrity rules* 9!e"e a"e tAo Inte+"it "ules3 +ntity ,ntegrity& States t!at S,"ima" <e cannot !a$e NULL $alueT -eferential ,ntegrity& States t!at SHo"ei+n 2e can be eit!e" a NULL $alue o" s!ould be ,"ima" 2e $alue of ot!e" "elation3 3. What is e.tension and intension? +.tension > It is t!e numbe" of tuples p"esent in a table at an instance3 9!is is time dependent3 ,ntension >

K.Ravi

32

DBMS Lab Manual It is a constant $alue t!at +i$es t!e name1 st"uctu"e of table and t!e const"aints laid on it3 4. What is System -? What are its t)o ma/or subsystems? S stem @ Aas desi+ned and de$eloped o$e" a pe"iod of &;/*>/; at IBM San 8ose @esea"c! Cente"3 It is a p"otot pe and its pu"pose Aas to demonst"ate t!at it is possible to build a @elational S stem t!at can be used in a "eal life en$i"onment to sol$e "eal life p"oblems1 Ait! pe"fo"mance at least compa"able to t!at of e6istin+ s stem3 Its tAo subs stems a"e @esea"c! Sto"a+e S stem @elational Data S stem3 5. 0o) is the data structure of System - different from the relational structure? Unli<e @elational s stems in S stem @ Domains a"e not suppo"ted Enfo"cement of candidate <e uni?ueness is optional Enfo"cement of entit inte+"it is optional @efe"ential inte+"it is not enfo"ced ". What is Data ,ndependence? Data independence means t!at St!e application is independent of t!e sto"a+e st"uctu"e and access st"ate+ of dataT3 In ot!e" Ao"ds1 9!e abilit to modif t!e sc!ema definition in one le$el s!ould not affect t!e sc!ema definition in t!e ne6t !i+!e" le$el3 9Ao t pes of Data Independence: ,! sical Data Independence: Modification in p! sical le$el s!ould not affect t!e lo+ical le$el3 Lo+ical Data Independence: Modification in lo+ical le$el s!ould affect t!e $ieA le$el3 123+& 'ogical Data ,ndependence is more difficult to achie!e 4. What is a !ie)? 0o) it is related to data independence? A $ieA ma be t!ou+!t of as a $i"tual table1 t!at is1 a table t!at does not "eall e6ist in its oAn "i+!t but is instead de"i$ed f"om one o" mo"e unde"l in+ base table3 In ot!e" Ao"ds1 t!e"e is no sto"ed file t!at di"ect "ep"esents t!e $ieA instead a definition of $ieA is sto"ed in data dictiona" 3 G"oAt! and "est"uctu"in+ of base tables is not "eflected in $ieAs3 9!us t!e $ieA can insulate use"s f"om t!e effects of "est"uctu"in+ and +"oAt! in t!e database3 Cence accounts fo" lo+ical data independence3

K.Ravi

33

DBMS Lab Manual

B" Database 'chema %or a Emplo)ee@pa) scenario


emplo ee7empAi3 0 integer1 empPname: st"in+: depa"tment73eptAi30 integer1 deptPname:st"in+: pa details7empAi3 0 integer1 3eptAi30 integer1 basic: inte+e"1 deductions: inte+e"1 additions: inte+e"1 DO8: date: pa "oll!empAi3 0 integer1 pa Pdate: date: For the abo4e schema, per%orm the %ollo9ingH a: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List t!e emplo ee details depa"tment Aise d: List all t!e emplo ee names A!o 'oined afte" pa"ticula" date e: List t!e details of emplo ees A!ose basic sala" is betAeen &=1=== and )=1=== f: Gi$e a count of !oA man emplo ees a"e Ao"<in+ in eac! depa"tment +: Gi$e a names of t!e emplo ees A!ose netsala" I&=1=== !: List t!e details fo" an emplo eePidR5 i: C"eate a $ieA A!ic! lists out t!e empPname1 depa"tment1 basic1 dedeuctions1 netsala" ': C"eate a $ieA A!ic! lists t!e empPname and !is netsala"

K.Ravi

34

DBMS Lab Manual AI(0 C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints Inse"t a"ound &= "eco"ds in eac! of t!e tables

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e

O"acle

C"eate table emplo ee7empPid numbe"75: p"ima" <e 1empPname $a"c!a")7)5::K S0LIdesc emplo eeK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 EM,PID NO9 NULL NUMBE@75: EM,PNAME %A@CCA@)7)5: 8ali3 /est Data0 S0LIinse"t into emplo ee $alues7[empPid1F[empPnameF:K S0LIselect Y f"om emplo eeK EM,PID EM,PNAME LLLLLLLLLLLLLLLLLLLLLL3 &= @obe"t )& Coult!a"d (= He"nando Alonso (; 2a"ti<e an 4/ 2immi S0LIc"eate table depa"tment7deptPid numbe"75: p"ima" <e 1deptPname $a"c!a")7)=::K S0LIdesc depa"tmentK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 DE,9PID NO9 NULL NUMBE@75: DE,9PNAME %A@CCA@)7)=: S0LIinse"t into depa"tment $alues7[deptPid1F[deptPnameF:K K.Ravi 35

DBMS Lab Manual S0LIselect Y f"om depa"tmentK DE,9PID DE,9PNAME LLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 &== sales &=& accounts &=) administ"ation &=( p"oduction &=* supe"$iso" S0LIc"eate table pa details7empPid numbe"75: "efe"ences emplo ee7empPid:1deptPid numbe"75: "ee"ences depa"tment7deptPid:1basic numbe"7/1):1deductions numbe"751):1additions numbe"751):1do' date:K S0LIdesc pa detailsK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 EM,PID NUMBE@75: DE,9PID NUMBE@75: BASIC NUMBE@7/1): DEDUC9IONS NUMBE@751): ADDI9IONS NUMBE@751): DO8 DA9E Di%%erent Data 'ets0 S0LIinse"t into pa deatils $alues7[empPid1[deptPid1 [basic1[deductions1[additions1[do':K S0LIselect Y f"om pa deatilsK EM,PID DE,9PID BASIC DEDUC9IONS ADDI9IONS DO8 LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 &= &=& )5=)(3&) *(3=; /&3)( =4>8AN>;( )& &== &=5==3); )(3;4 *=3; =&>8AN>=. (= &=) .5==35 (=35* &5 =.>8UL>;/ (; &=( ;/==3*5 ()3/4 .53=; =4>AUG>=( 4/ &=* &5=== ;/3.. &5*34 )*>SE,>=* S0LIc"eate table pa "oll7empPid numbe"75:"efe"ences emplo ee7empPid:1pa Pdate date:K S0LIdesc pa "ollK Name K.Ravi NullZ 9 pe 36

DBMS Lab Manual LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 EM,PID NUMBE@75: ,AJPDA9E DA9E S0LIinse"t into pa "oll $alues7[empPid1F[dateF:K S0LIselect Y f"om pa "ollK EM,PID ,AJPDA9E LLLLLLLLLLLLLLLLLLLLLL3 &= (&>8AN>=. )& =(>HEB>=. (= &5>8AN>=. (; )/>8AN>=. 4/ =*>HEB>=. c$ List t!e emplo ee details depa"tment Aise S0LIselect empid1deptid f"om pa detK EM,ID DE,9ID LLLLLLLLLL *=& 5== *=) )== *=( .== *=* *== *=5 &)== d: List all t!e emplo ee names A!o 'oined afte" pa"ticula" date S0LIselect e1empname f"om emplo ee e1pa det p A!e"e e3empidRp3empid and p3do'IRF=5>ma">=.FK EM,NAME LLLLLLL A%INASC NI9IN ,CALGUN e: List t!e details of emplo ees A!ose basic sala" is betAeen &=1=== and )=1=== s?LI Select empid1empname f"om emplo ee A!e"e sala" betAeen &==== and )====K EM,ID K.Ravi EM,NAME 37

DBMS Lab Manual LLLLLLLLLLL3 *=) A2CILA *=( aaaaaaaa EM,ID EM,NAME LLLLLLLLLLL3 A2CILA %: Gi$e a count of !oA man emplo ees a"e Ao"<in+ in eac! depa"tment S0LIselect count7empid:1deptid f"om pa det +"oup b deptidK COUN9 7EM,ID: DE,9ID LLLLLLLLLLLLLLLLLLLLL & )== & *== & 5== & .== & &)== g: Gi$e a names of t!e emplo ees A!ose netsala" I&=1=== S0LI select empname f"om emplo ee A!e"e empid in7select empid f"om pa det A!e"e basic>deductionI&====:K EM,NAME LLLLLL A%INASC A2CILA CA@ISC NI9IN ,CALGUN !: List t!e details fo" an emplo eePidR5 S0LI select Y f"om emplo ee A!e"e empidR5K EM,ID EM,NAME >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 5 Coult!a"d

K.Ravi

38

DBMS Lab Manual i: C"eate a $ieA A!ic! lists out t!e empPname1 depa"tment1 basic1 dedeuctions1 netsala" C"eate a $ieA A!ic! lists t!e empPname and !is netsala"

':

8i4a@8ice0 %3. What is Data Model? A collection of conceptual tools fo" desc"ibin+ data1 data "elations!ips data semantics and const"aints3 %4. What is +5- model? 9!is data model is based on "eal Ao"ld t!at consists of basic ob'ects called entities and of "elations!ip amon+ t!ese ob'ects3 Entities a"e desc"ibed in a database b a set of att"ibutes3 %5. What is 2b/ect 2riented model? 9!is model is based on collection of ob'ects3 An ob'ect contains $alues sto"ed in instance $a"iables Ait! in t!e ob'ect3 An ob'ect also contains bodies of code t!at ope"ate on t!e ob'ect3 9!ese bodies of code a"e called met!ods3 Ob'ects t!at contain same t pes of $alues and t!e same met!ods a"e +"ouped to+et!e" into classes3 %". %4. %6. What is an +ntity? It is a \t!in+\ in t!e "eal Ao"ld Ait! an independent e6istence3 What is an +ntity type? It is a collection 7set: of entities t!at !a$e same att"ibutes3 What is an +ntity set? It is a collection of all entities of pa"ticula" entit t pe in t!e database3

K.Ravi

39

DBMS Lab Manual

C" Database 'chema %or a 8i3eo *ibrar) scenario


Custome"7custPno: inte+e"1custPname: st"in+: Membe"s!ip7(emAno0 integer1 c&stAno0 integer: Cassette7cassAno0integer1 cassPname:st"in+1 Lan+ua+e: St"in+: IssP"ec!issAno0 integer1 issPdate: date1 memAno0 integer1 cassAno0 integer: For the abo4e schema, per%orm the %ollo9ingH a: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List all t!e custome" names Ait! t!ei" membe"s!ip numbe"s d: List all t!e issues fo" t!e cu""ent date Ait! t!e custome" names and cassette names e: List t!e details of t!e custome" A!o !as bo""oAed t!e cassette A!ose title is S 9!e Le+endT f: Gi$e a count of !oA man cassettes !a$e been bo""oAed b eac! custome" +: Gi$e a list of boo< A!ic! !as been ta<en b t!e student Ait! memPno as 5 !: List t!e cassettes issues fo" toda i: C"eate a $ieA A!ic! lists outs t!e issPno1 issPdate1 custPname1 cassPname ': C"eate a $ieA A!ic! lists issues>date Aise fo" t!e last one Aee<

K.Ravi

40

DBMS Lab Manual

AI(0 C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints


Inse"t a"ound &= "eco"ds in eac! of t!e tables

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e

O"acle

S0LIc"eate table custome"7custPno numbe"75: p"ima" <e 1custPname $a"c!a")7)=::K S0LIdesc custome"K Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 CUS9PNO NO9 NULL NUMBE@75: CUS9PNAME %A@CCA@)7)=: 8ali3 /est Data0 S0LIinse"t into custome" $alues7[custPno1F[custPnameF:K S0LIselect Y f"om custome"K CUS9PNO CUS9PNAME LLLLLLLLLLLLLLLLLLLLLLLL3 5= scott 5& pande 5) $a"s!ne 5( naidu 5* b!imb"a S0LIc"eate table membe"s!ip7memPno numbe"75: p"ima" <e 1custPno numbe"75: "efe"ences custome"7custPno::K S0LIdsec membe"s!ipK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL333 MEMPNO NO9 NULL NUMBE@75: CUS9PNO NUMBE@75:

K.Ravi

41

DBMS Lab Manual S0LIinse"t into mems!ip $alues7[memPno1[custPno:K S0LIselect Y f"om mems!ipK MEMPNO CUS9PNO LLLLLLLLLLLLLLLLLLL ;)= 5= ;4& 5& 4;/ 5) 4)= 5( ;)4 5* S0LIc"ea te table cassette7cassPno numbe"75: p"ima" <e 1 CassPname $a"c!a")7&5:1lan+ua+e $a"c!a")7&5::K S0LIdesc cassetteK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL33 CASSPNO NO9 NULL NUMBE@75: CASSPNAME %A@CCA@)7&5: LANGUAGE %A@CCA@)7&5: S0LIinse"t into cassette $alues7[cassPno1F[cassPnameF1F[lan+ua+eF:K S0LIselect Y f"om cassetteK CASSPNO CASSPNAME LANGUAGE LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL & ta+o"e telu+u ) t!e lion <in+ En+lis! ( anni an tamil * ind"a telu+u 5 lo"d of "in+s En+lis! S0LIc"eate table issuP"ec7issPno numbe"75: p"ima" <e 1issPdate date1memPno numbe"75:"efe"ences mems!ip7memPno:1cassPno numbe"75: "efe"ences cassette7cassPno::K S0LIdesc issuP"ecK Name NullZ 9 pe LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL333 ISSPNO NO9 NULL NUMBE@75: ISSPDA9E DA9E MEMPNO NUMBE@75: K.Ravi 42

DBMS Lab Manual CASSPNO S0LIselect Y f"om issuP"ecK ISSPNO ISSPDA9E MEMPNO CASSPNO LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL )) =/>8AN>=. ;)= & )( &=>8AN>== ;4& ) ). &=>8AN>=. 4;/ 5 ( =&>8AN>=. 4)= * (* (&>DEC>=5 ;)4 ( c: List all t!e custome" names Ait! t!ei" membe"s!ip numbe"s S0LIselect c3custname1m3memno f"om custome"& c1membe"s!ip& m A!e"e c3custnoRm3custnoK CUS9NAME MEMNO LLLLLL33 LLLLLL33 NI2CIL 5& %I%E2 5) SC@A%AN 54 %AMSI 5/ SCI%A 5. d: List all t!e issues fo" t!e cu""ent date Ait! t!e custome" names and cassette names S0LIselect i3issno1c3custname1cc3cassettename f"om custome"& c1membe"s!ip& m1cassette cc1iss"ec& I A!e"e i3issdateRtoPc!a"7s sdate: and c3custnoRm3custno and i3cassnoRcc3cassno and i3memnoRm3memnoK 1&t#&t0 no "oAs selected3 e: List t!e details of t!e custome" A!o !as bo""oAed t!e cassette A!ose title is S 9!e Le+endT f: Gi$e a count of !oA man cassettes !a$e been bo""oAed b eac! custome" +: Gi$e a list of boo< A!ic! !as been ta<en b t!e student Ait! memPno as 5 !: List t!e cassettes issues fo" toda K.Ravi 43 NUMBE@75:

DBMS Lab Manual i: C"eate a $ieA A!ic! lists outs t!e issPno1 issPdate1 custPname1 cassPname ': C"eate a $ieA A!ic! lists issues>date Aise fo" t!e last one Aee< 8i4a@8ice0 %7. What is an +.tension of entity type? 9!e collections of entities of a pa"ticula" entit to+et!e" into an entit set3 28. t pe a"e +"ouped

What is Wea9 +ntity set? An entit set ma not !a$e sufficient att"ibutes to fo"m a p"ima" <e 1 and its p"ima" <e comp"omises of its pa"tial <e and p"ima" <e of its pa"ent entit 1 t!en it is said to be Dea< Entit set3 2%. 22. What is an attribute? It is a pa"ticula" p"ope"t 1 A!ic! desc"ibes t!e entit 3

What is a -elation Schema and a -elation? A "elation Sc!ema denoted b @7A&1 A)1 L1 An: is made up of t!e "elation name @ and t!e list of att"ibutes Ai t!at it contains3 A "elation is defined as a set of tuples3 Let " be t!e "elation A!ic! contains set tuples 7t&1 t)1 t(1 3331 tn:3 Eac! tuple is an o"de"ed list of n>$alues tR7$&1$)1 3331 $n:3 23. 24. 25. What is degree of a -elation? It is t!e numbe" of att"ibute of its "elation sc!ema3 What is -elationship? It is an association amon+ tAo o" mo"e entities3 What is -elationship set? 9!e collection 7o" set: of simila" "elations!ips3

K.Ravi

44

DBMS Lab Manual

5"Database 'chema %or a st&3ent@*ab scenario


Student7st&3Ano0 integer1 studPname: st"in+1 class0 string: Class7class0 string, 3escrip0 string: Lab7machAno0 integer1 LabPno: inte+e"1 desc"iption: St"in+: Allotment7't&3Ano0 Integer, machAno0 integer, 3a)o% 9ee=0 string$ For the abo4e schema, per%orm the %ollo9ingH a: C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints b: Inse"t a"ound &= "eco"ds in eac! of t!e tables c: List all t!e mac!ine allotments Ait! t!e student names1 lab and mac!ine numbe"s d: List t!e total numbe" of lab allotments da Aise e: Gi$e a count of !oA man mac!ines !a$e been allocated to t!e MCSI9F class f: Gi$e a mac!ine allotment etails of t!e studPno 5 Ait! !is pe"sonal and class details g) Count fo" !oA man mac!ines !a$e been allocatedin *abAno 1 fo" t!e da of t!e Aee< as SMonda T !: CoA man students class Aise !a$e allocated mac!ines in t!e labs i: C"eate a $ieA A!ic! lists out t!e studPno1 studPname1 mac!Pno1 labPno1 da ofAee< j) C"eate a $ieA A!ic! lists t!e mac!ine allotment details fo" S9!u"sda T

K.Ravi

45

DBMS Lab Manual AI(0 C"eate t!e tables Ait! t!e app"op"iate inte+"it const"aints Inse"t a"ound &= "eco"ds in eac! of t!e tables

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e

O"acle

S0LIc"eate table stu7studPno numbe"75: p"ima" <e 1studPnam $a"c!a")7)=:1class $a"c!a")7)=::K S0LI desc stuK Name S9UDPNO S9UDPNAM CLASS 8ali3 Data 'ets0 S0LI inse"t into stu $alues7[studPno1F[studPnamF1F[classF:K S0LI select Y f"om stuK S9UDPNO (; (* &4 4 )* S9UDPNAM LEON %I2AS MA9CED CANSEN ALEEIS CLASS CSE CSI9 ECE MECC EEE nullZ NO9 NULL 9 pe NUMBE@75: %A@CCA@)7)=: %A@CCA@)7)=:

S0LI C"eate table class 7class $a"c!a")7)=:1 desc"ipt $a"c!a")7&=::K S0LI Desc"ibe classK Name CLASS DESC@I,9 null t pe %A@CCA@)7&=: %A@CCA@)7)=:

S0LI c"eate table lab7matc!Pno numbe"75:1 labPno numbe"75:1 desc"iption $a"c!a")7)=::K

K.Ravi

46

DBMS Lab Manual

S0LI desc labK Name MACCPNO LABPNO DESC@I,9ION null NO9 NULL t pe NUMBE@75: NUMBE@75: %A@CCA@)7)=:

S0LI inse"t into lab $alues7[mac!Pno1[labPno1F[desc"iptionF:K S0LI select Y f"om labK MA9CCPNO LABPNO DESC@I,9ION >>>>>>>>>>>>>>> >>>>>>>>> >>>>>>>>>>>>>>>>>>>> )( / p! sics /4 ) c!emist" 4/ & edc &) &= cds 4 ( 'a$a lab S0LI c"eate table allotment7studPno numbe"75: "efe"ences stu7studPno:1 matc!Pno numbe"75: "efe"ences lab7mac!Pno:1 DoAee< $a"c!a")7)=::K S0LI desc allotmentK Name >>>>>>>>>>>>>> S9UDPNO MACCPNO DODEE2 NullZ >>>>>>> 9 pe >>>>>>>>> NUMBE@75: NUMBE@75: %A@CCA@)7)=:

S0LIselect Y f"om allotmentK S9UDPNO >>>>>>>>>>>>>>> (; (* &4 4 )* MACCPNO >>>>>>>>>>>> )( 4/ /4 &) &) DODEE2 >>>>>>>>>>>> sat mon tue Aed t!u

K.Ravi

47

DBMS Lab Manual

c: List all t!e mac!ine allotments Ait! t!e student names1 lab and mac!ine numbe"s S0LIselect s3studname1l3mac!no f"om student& s1lab l1allotment a A!e"e a3mac!noRl3mac!no and a3studnoRs3studnoK S9UDNAME MACCNO LLLLLLLLLLLLLLL33 ABCI8EE9 & 2ALJAN )) ASCDIN ( A@2A * A@%IND 5 d: List t!e total numbe" of lab allotments da Aise S0LIselect l3mac!no1l3desc"ip1a3da f"om lab l1allotment a A!e"e a3mac!noRl3mac!noK MACCNO DESC@I, DAJ LLLLLLLLLLLLLLLLLLLLLLLLLL & UNIE MONDAJ )) UNIE 9UESDAJ ( E, DEDNESDAJ * DINDODS 9C@USDAJ 5 ME H@IDAJ e: Gi$e a count of !oA man mac!ines !a$e been allocated to t!e MCSI9F class S0LIselect count7mac!no:f"om allotment A!e"e studno in7select studno f"om student& A!e"e classRFCSI9F:K COUN9 7MACCNO: LLLLLLLL33 & f: Gi$e a mac!ine allotment etails of t!e studPno 5 Ait! !is pe"sonal and class details S0LIselect a3studno1a3mac!no1s3studname1s3class f"om allotment a1student& s A!e"e a3studnoRs3studno and a3studnoR5=(K K.Ravi 48

DBMS Lab Manual

S9UDNO MACCNO S9UDNAME CLASS LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL 5=( 5 A@%IND CSE g) Count fo" !oA man mac!ines !a$e been allocatedin *abAno 1 fo" t!e da of t!e Aee< as SMonda T !: CoA man students class Aise !a$e allocated mac!ines in t!e labs S0LIselect count7studno: Sallocated students in t!e labsT1class f"om student& A!e"e studno in7select studno f"om allotment: +"oup b classK allocated students in t!e lab CLASS LLLLLLLLLLLLLLLLLLLLLLLLLLLLL ) CSE & ECE & EEE & I9 i: C"eate a $ieA A!ic! lists out t!e studPno1 studPname1 mac!Pno1 labPno1 da ofAee< ': C"eate a $ieA A!ic! lists t!e mac!ine allotment details fo" S9!u"sda T

8i4a@8ice0 2". What is -elationship type? @elations!ip t pe defines a set of associations o" a "elations!ip set amon+ a +i$en set of entit t pes3 24. 25. What is degree of -elationship type? It is t!e numbe" of entit t pe pa"ticipatin+3 a

What is DD' :Data Definition 'anguage;? A data base sc!ema is specifies b a set of definitions e6p"essed b special lan+ua+e called DDL3

K.Ravi

49

DBMS Lab Manual 2". 24. What is (D' :(ie) Definition 'anguage;? It specifies use" $ieAs and t!ei" mappin+s to t!e conceptual sc!ema3

What is SD' :Storage Definition 'anguage;? 9!is lan+ua+e is to specif t!e inte"nal sc!ema3 9!is lan+ua+e ma specif t!e mappin+ betAeen tAo sc!emas3 26. What is Data Storage 5 Definition 'anguage? 9!e sto"a+e st"uctu"es and access met!ods used b database s stem a"e specified b a set of definition in a special t pe of DDL called data sto"a+e>definition lan+ua+e3 27. What is DM' :Data Manipulation 'anguage;? 9!is lan+ua+e t!at enable use" to access o" manipulate data as o"+anised b app"op"iate data model3 $rocedural DM' or 'o) le!el& DML "e?ui"es a use" to specif A!at data a"e needed and !oA to +et t!ose data3 1on5$rocedural DM' or 0igh le!el& DML "e?ui"es a use" to specif A!at data a"e needed Ait!out specif in+ !oA to +et t!ose data3 3%. What is DM' <ompiler? It t"anslates DML statements in a ?ue" lan+ua+e into loA>le$el inst"uction t!at t!e ?ue" e$aluation en+ine can unde"stand3

K.Ravi

50

DBMS Lab Manual

$" ;rite a program to %in3 largest n&mber %rom the gi4en three n&mbers"
Aim0 9o find la"+est numbe" f"om t!e +i$en t!"ee numbe"s3

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e
Algorithm0

O"acle1 ,lS0L

Step &: Decla"e t!e $a"iable A1 B1 and C3 Step ): Sto"e t!e $alid data3 Step (: Compa"e $a"iable A Ait! B and A Ait! C Step *: If t!e $alue sto"ed in $a"iable A is bi+1 it displa s SA is Bi+T3 7IH conditional statement s!ould be used: Step 5: Compa"e $a"iable B Ait! C Step .: If t!e $alue sto"ed in $a"iable B is bi+1 it displa s SB is Bi+T3 Step /: ot!e" Aise it displa s SC is Bi+T Decla"e A numbe"K B numbe"K C numbe"K Be+in A:R[aK B:R[bK C:R[cK If a I b [[ aI c t!en

K.Ravi

51

DBMS Lab Manual DbmsPoutput3putPline7M A is bi+ M:K Else If7 bIc [[ bI a : t!en DbmsPoutput3putPline7M B is bi+ M:K Else DbmsPoutput3putPline7M C is bi+ M:K End ifK End ifK EndK 8ali3 Data 'ets0 Ente" t!e $alue of a: & Ente" t!e $alue of b: ) Ente" t!e $alue of c: ( 1U/#U/0 C is bi+ In4ali3 Data sets 0 Ente" t!e $alue of a: Ente" t!e $alue of b: 6 Ente" t!e $alue of c: a 1&tp&t0 In$alid data t pes3 8i4a@8ice0 K.Ravi 52

DBMS Lab Manual (&3 D!at is ,l>S0L Z ,"ocedu"al Lan+ua+e St"uctu"ed 0ue" Lan+ua+e 32. 33. What is =uery e!aluation engine? It e6ecutes loA>le$el inst"uction +ene"ated b compile"3

What is DD' ,nterpreter? It inte"p"ets DDL statements and "eco"d t!em in tables containin+ metadata3 34. What is -ecord5at5a5time? 9!e LoA le$el o" ,"ocedu"al DML can specif and "et"ie$e eac! "eco"d f"om a set of "eco"ds3 9!is "et"ie$e of a "eco"d is said to be @eco"d>at>a> time3 35. What is Set5at5a5time or Set5oriented? 9!e Ci+! le$el o" Non>p"ocedu"al DML can specif and "et"ie$e man "eco"ds in a sin+le DML statement3 9!is "et"ie$e of a "eco"d is said to be Set> at>a>time o" Set>o"iented3 3". What is -elational lgebra? It is p"ocedu"al ?ue" lan+ua+e3 It consists of a set of ope"ations t!at ta<e one o" tAo "elations as input and p"oduce a neA "elation3 34. What is -elational <alculus? It is an applied p"edicate calculus specificall tailo"ed fo" "elational databases p"oposed b E3H3 Codd3 E3+3 of lan+ua+es based on it a"e DSL AL,CA1 0UEL3

K.Ravi

53

DBMS Lab Manual

,$" 'imple programs &sing loop, 9hile an3 %or iterati4e control statement"
a$ 9o +ene"ate fi"st &= natu"al numbe"s usin+ loop, 9hile and %or3 AI(0 9o +ene"ate fi"st &= natu"al numbe"s usin+ loop1 A!ile and fo"3

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e
Algorithm0 Step Step Step Step Step Step Step &: ): (: *: 5: .: /:

O"acle1 ,lS0L

Decla"e t!e $a"iable I3 Sto"e t!e $alid data & in I3 Use *11# statement Displa t!e fi"st $alue3 Inc"ement t!e $alue of I b & $alue3 c!ec< t!e $alue up to &= no3 and "epeat t!e loop If condition e6ceeds t!e +i$en $alue &=1 t!e loop Aill be te"minated3

?J &sing loop statement J? Decla"e I numbe"K Be+in I:R&K Loop DbmsPoutput3putPline7I:K I:RIG&K

K.Ravi

54

DBMS Lab Manual E6it A!en II&=K End loopK EndK

Algorithm0 %or ;2I*E loop Step Step Step Step Step Step Step &: ): (: *: 5: .: /: Decla"e t!e $a"iable I3 Sto"e t!e $alid data & in I3 Use ;2I*E statement C!ec< t!e $alue of I Ait! $alue &=3 if t!e $alue of I "eac!ed to &= t!e loop Aill be te"minated ot!e"Aise displa $alue of I inc"ement t!e ne6t $alue of I usin+ IRIG&3

?J &sing 9hile J? Decla"e I numbe"K Be+in I:R&K D!ile 7IVR&=: loop DbmsPoutput3putPline7I:K I:RIG&K End loopK EndK

K.Ravi

55

DBMS Lab Manual Algorithm0 Step &: Decla"e t!e $a"iable I3 Step ): Sto"e t!e $alue & in $a"3 I3 Step (: Use ForL *11# statement Step *: Displa t!e fi"st $alue of I3 Step 5: Inc"ement t!e $alue of I b & $alue3 Step .: c!ec< t!e $alue up to &= no3 and "epeat t!e loop Step /: if t!e loop e6ceeds t!e $alue &= t!en t!e loop Aill be te"minated3 ?J &sing %or loopJ? Be+in Ho" I in &33&= loop DbmsPoutput3putPline7I:K End loopK EndK 8ali3 /est Data: 1U/#U/ & ) ( * 5 . / 4 ; &=

K.Ravi

56

DBMS Lab Manual

8i4a@8ice0
38.

0o) does 3uple5oriented relational calculus differ from domain5 oriented relational calculus

9!e tuple>o"iented calculus uses a tuple $a"iables i3e31 $a"iable A!ose onl pe"mitted $alues a"e tuples of t!at "elation3 E3+3 0UEL 9!e domain>o"iented calculus !as domain $a"iables i3e31 $a"iables t!at "an+e o$e" t!e unde"l in+ domains instead of o$e" "elation3 E3+3 ILL1 DEDUCE3 37. What is normali>ation? It is a p"ocess of anal sin+ t!e +i$en "elation sc!emas based on t!ei" Hunctional Dependencies 7HDs: and p"ima" <e to ac!ie$e t!e p"ope"ties Minimi#in+ "edundanc Minimi#in+ inse"tion1 deletion and update anomalies3 48. What is #unctional Dependency? A Hunctional dependenc is denoted b E J betAeen tAo sets of att"ibutes E and J t!at a"e subsets of @ specifies a const"aint on t!e possible tuple t!at can fo"m a "elation state " of @3 9!e const"aint is fo" an tAo tuples t& and t) in " if t&WEX R t)WEX t!en t!e !a$e t&WJX R t)WJX3 9!is means t!e $alue of E component of a tuple uni?uel dete"mines t!e $alue of component J3 4%. When is a functional dependency # said to be minimal? E$e" dependenc in H !as a sin+le att"ibute fo" its "i+!t !and side3 De cannot "eplace an dependenc E A in H Ait! a dependenc J A A!e"e J is a p"ope" subset of E and still !a$e a set of dependenc t!at is e?ui$alent to H3 De cannot "emo$e an dependenc f"om H and still !a$e set of dependenc t!at is e?ui$alent to H3 42. What is Multi!alued dependency? Multi$alued dependenc denoted b E J specified on "elation sc!ema @1 A!e"e E and J a"e bot! subsets of @1 specifies t!e folloAin+ const"aint on an "elation " of @: if tAo tuples t& and t) e6ist in " suc! t!at t&WEX R t)WEX t!en t( and t* s!ould also e6ist in " Ait! t!e folloAin+ p"ope"ties t(W6X R t*WEX R t&WEX R t)WEX t(WJX R t&WJX and t*WJX R t)WJX t(W]X R t)W]X and t*W]X R t&W]X A!e"e W] R 7@>7E U J:: X

K.Ravi

57

DBMS Lab Manual 43. What is 'ossless /oin property? It +ua"antees t!at t!e spu"ious tuple +ene"ation does not occu" Ait! "espect to "elation sc!emas afte" decomposition3

K.Ravi

58

DBMS Lab Manual

D" #rogram to chec= Armstrong or not"

9hether

gi4en

n&mber

is

AI(0 to c!ec< A!et!e" +i$en numbe" is A"mst"on+ o" not3

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e
Algorithm0

O"acle1 ,l>S0L

Step &: Decla"e t!e $a"iable N1 S1 D and DU,3 Step ): Sto"e t!e $alue in $a"3 N and $a"3 DU,33 Step (: c!ec< fo" t!e $alue of N1 A!ic! is not e?ual to =3 Step *: di$ide $alue sto"ed in N b &= and sto"e it $a"3 D3 7DRnU&=:3 Step 5: t!e "eminde" Aill be multipl ( times and sto"e it in %a"3 S3 Step .: 9!e coefficient Aill be calculated usin+ HLOO@ function3 And sto"e it in $a"3 N3 Step /: "epeat t!e Steps (1 *1 51 and . till loop Aill be te"minated3 Step 4: C!ec< A!et!e" t!e sto"ed $alue and calculated $alues a"e same Step ;: if bot! t!e $alues a"e same1 t!en displa S9!e +i$en numbe" is A"mst"on+T Step &=: Ot!e"Aise displa Sit is not A"mst"on+T and te"minate t!e loop3 Decla"e N numbe"K S numbe"K D numbe"K Be+in N:R[nK S:R=K D!ile7n^R=:

K.Ravi

59

DBMS Lab Manual Loop DRnU&=K S:RsG7DYDYD:K N:Rfloo"7n/&=:K End loopK If 7DU,RS: t!en DBMSPoutput3putPline7Mnumbe" is a"mst"on+F:K Else DBMSPoutput3putPline7Mnumbe" is not a"mst"on+F:K End ifK EndK /est 8ali3 Data 'et0 Ente" $alue of n &5( 1U/#U/0 numbe" is A"mst"on+3 8i4a@8ice0 44. What is 1 NF (Normal Form)? !" #$%ain $& a''(ibu'" %u)' in*lu#" $nl+ a'$%i* ,)i%-l". in#ivi)ibl") valu"). 45. What is Fully Functional dependency? /' i) ba)"# $n *$n*"-' $& &ull &un*'i$nal #"-"n#"n*+. A &un*'i$nal #"-"n#"n*+ 0 1 i) &ull &un*'i$nal #"-"n#"n*+ i& ("%$val $& an+ a''(ibu'" A &($% 0 %"an) '!a' '!" #"-"n#"n*+ #$") n$' !$l# an+ %$(". 46. What is 2NF? A ("la'i$n )*!"%a R i) in 223 i& i' i) in 123 an# "v"(+ n$n4-(i%" a''(ibu'" A in R i) &ull+ &un*'i$nall+ #"-"n#"n' $n -(i%a(+ 5"+. 47. What is 3NF?

K.Ravi

60

DBMS Lab Manual A ("la'i$n )*!"%a R i) in 323 i& i' i) in 223 an# &$( "v"(+ 3D 0 A "i'!"( $& '!" &$ll$6ing i) '(u" 0 i) a Su-"(45"+ $& R. A i) a -(i%" a''(ibu'" $& R. /n $'!"( 6$(#). i& "v"(+ n$n -(i%" a''(ibu'" i) n$n4'(an)i'iv"l+ #"-"n#"n' $n -(i%a(+ 5"+. 4 . What is !"NF (!oyce#"odd Normal Form)? A ("la'i$n )*!"%a R i) in BC23 i& i' i) in 323 an# )a'i)&i") an a##i'i$nal *$n)'(ain' '!a' &$( "v"(+ 3D 0 A. 0 %u)' b" a *an#i#a'" 5"+. 4$. What is 4NF? A ("la'i$n )*!"%a R i) )ai# '$ b" in 423 i& &$( "v"(+ Mul'ivalu"# #"-"n#"n*+ 1 '!a' !$l#) $v"( R. $n" $& &$ll$6ing i) '(u" 0 i) )ub)"' $( "7ual '$ ,$() 01 8 R. 0 i) a )u-"( 5"+. 0

K.Ravi

61

DBMS Lab Manual

:" ;rite a program to generate all prime n&mbers belo9 100"


AI(: to +ene"ate all p"ime numbe"s beloA &==3

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e
Decla"e I numbe"K 8 numbe"K C numbe"K Be+in D!ile7iVR&==: Loop C:R=K 8:R&K D!ile7'VRi: Loop

O"acle1 ,lS0L

If7floo"7iU':R=: t!en C:R CG&K End ifK 8:R'G&K End loopK

K.Ravi

62

DBMS Lab Manual If7cR): t!en DbmsPoutput3putPline7i:K End ifK EndloopK EndK 8ali3 /est Data 1U/#U/0 ) ( 5 / && 3 3 ;; 8i4a@8ice0 5%. What is 5NF? A R"la'i$n )*!"%a R i) )ai# '$ b" 523 i& &$( "v"(+ j$in #"-"n#"n*+ 9R1. R2. .... Rn: '!a' !$l#) R. $n" '!" &$ll$6ing i) '(u" Ri 8 R &$( )$%" i. !" j$in #"-"n#"n*+ i) i%-li"# b+ '!" )"' $& 3D. $v"( R in 6!i*! '!" l"&' )i#" i) 5"+ $& R. 51. What is &omain#'ey Normal Form? A ("la'i$n i) )ai# '$ b" in DK23 i& all *$n)'(ain') an# #"-"n#"n*i") '!a' )!$ul# !$l# $n '!" '!" *$n)'(ain' *an b" "n&$(*"# b+ )i%-l+ "n&$(*ing '!" #$%ain *$n)'(ain' an# 5"+ *$n)'(ain' $n '!" ("la'i$n. 52. What are partial( alternate(( arti)icial( compound and natural *ey? +artial 'ey, /' i) a )"' $& a''(ibu'") '!a' *an uni7u"l+ i#"n'i&+ 6"a5 "n'i'i") an# '!a' a(" ("la'"# '$ )a%" $6n"( "n'i'+. /' i) )$%"'i%" *all"# a) Di)*(i%ina'$(.

K.Ravi

63

DBMS Lab Manual -lternate 'ey, All Can#i#a'" K"+) ";*lu#ing '!" <(i%a(+ K"+ a(" 5n$6n a) Al'"(na'" K"+). -rti)icial 'ey= /& n$ $bvi$u) 5"+. "i'!"( )'an# al$n" $( *$%-$un# i) availabl". '!"n '!" la)' (")$(' i) '$ )i%-l+ *("a'" a 5"+. b+ a))igning a uni7u" nu%b"( '$ "a*! ("*$(# $( $**u(("n*". !"n '!i) i) 5n$6n a) #"v"l$-ing an a('i&i*ial 5"+. "ompound 'ey: /& n$ )ingl" #a'a "l"%"n' uni7u"l+ i#"n'i&i") $**u(("n*") 6i'!in a *$n)'(u*'. '!"n *$%bining %ul'i-l" "l"%"n') '$ *("a'" a uni7u" i#"n'i&i"( &$( '!" *$n)'(u*' i) 5n$6n a) *("a'ing a *$%-$un# 5"+. Natural 'ey: >!"n $n" $& '!" #a'a "l"%"n') )'$("# 6i'!in a *$n)'(u*' i) u'ili?"# a) '!" -(i%a(+ 5"+. '!"n i' i) *all"# '!" na'u(al 5"+. 53. What is inde.in/ and 0hat are the di))erent *inds o) inde.in/? /n#";ing i) a '"*!ni7u" &$( #"'"(%ining !$6 7ui*5l+ )-"*i&i* #a'a *an b" &$un#. +-")= Bina(+ )"a(*! )'+l" in#";ing B4 ("" in#";ing /nv"('"# li)' in#";ing M"%$(+ (")i#"n' 'abl" abl" in#";ing

K.Ravi

64

DBMS Lab Manual

10" ;rite a statement"

program

to

3emonstrate

the

G1/1

AI(: to demonst"ate t!e GO9O statement

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e

O"acle1 ,lS0L

Decla"e I numbe"K Be+in I:R&K If7iIR=: t!en GO9O !e"eK Else DbmsPoutput3putPline7 M I is ne+ati$eF:K End ifK VV!e"eII DbmsPoutput3putPline7 M I is positi$eF:K EndK 8ali3 /est Data 1U/#U/0 I is positi$e K.Ravi 65

DBMS Lab Manual 8i4a@8ice0 54. What is system catalo/ or catalo/ relation? 1o0 is 2etter *no0n as? A RDBMS %ain'ain) a #")*(i-'i$n $& all '!" #a'a '!a' i' *$n'ain). in&$(%a'i$n ab$u' "v"(+ ("la'i$n an# in#"; '!a' i' *$n'ain). !i) in&$(%a'i$n i) )'$("# in a *$ll"*'i$n $& ("la'i$n) %ain'ain"# b+ '!" )+)'"% *all"# %"'a#a'a. /' i) al)$ *all"# #a'a #i*'i$na(+. 55. What is meant 2y 3uery optimi4ation? !" -!a)" '!a' i#"n'i&i") an "&&i*i"n' ";"*u'i$n -lan &$( "valua'ing a 7u"(+ '!a' !a) '!" l"a)' ")'i%a'"# *$)' i) ("&"(("# '$ a) 7u"(+ $-'i%i?a'i$n. 56. What is 5oin dependency and inclusion dependency? 6oin &ependency, A @$in #"-"n#"n*+ i) g"n"(ali?a'i$n $& Mul'ivalu"# #"-"n#"n*+.A @D 9R1. R2. .... Rn: i) )ai# '$ !$l# $v"( a ("la'i$n R i& R1. R2. R3. .... Rn i) a l$))l"))4j$in #"*$%-$)i'i$n $& R . !"(" i) n$ )"' $& )$un# an# *$%-l"'" in&"("n*" (ul") &$( @D. 7nclusion &ependency, An /n*lu)i$n D"-"n#"n*+ i) a )'a'"%"n' $& '!" &$(% '!a' )$%" *$lu%n) $& a ("la'i$n a(" *$n'ain"# in $'!"( *$lu%n). A &$("ign 5"+ *$n)'(ain' i) an ";a%-l" $& in*lu)i$n #"-"n#"n*+. 57. What is dura2ility in &!89? An*" '!" DBMS in&$(%) '!" u)"( '!a' a '(an)a*'i$n !a) )u**"))&ull+ *$%-l"'"#. i') "&&"*') )!$ul# -"()i)' "v"n i& '!" )+)'"% *(a)!") b"&$(" all i') *!ang") a(" ("&l"*'"# $n #i)5. !i) -($-"('+ i) *all"# #u(abili'+. 5 . What do you mean 2y atomicity and a//re/ation? -tomicity, Bi'!"( all a*'i$n) a(" *a((i"# $u' $( n$n" a(". C)"() )!$ul# n$' !av" '$ 6$((+ ab$u' '!" "&&"*' $& in*$%-l"'" '(an)a*'i$n). DBMS "n)u(") '!i) b+ un#$ing '!" a*'i$n) $& in*$%-l"'" '(an)a*'i$n). -//re/ation, A *$n*"-' 6!i*! i) u)"# '$ %$#"l a ("la'i$n)!i- b"'6""n a *$ll"*'i$n $& "n'i'i") an# ("la'i$n)!i-). /' i) u)"# 6!"n 6" n""# '$ ";-(")) a ("la'i$n)!i- a%$ng ("la'i$n)!i-). 5$. What is a +hantom &eadloc*? /n #i)'(ibu'"# #"a#l$*5 #"'"*'i$n. '!" #"la+ in -($-aga'ing l$*al in&$(%a'i$n %ig!' *au)" '!" #"a#l$*5 #"'"*'i$n alg$(i'!%) '$ i#"n'i&+ #"a#l$*5) '!a' #$ n$' ("all+ ";i)'. Su*! )i'ua'i$n) a(" *all"# -!an'$% #"a#l$*5) an# '!"+ l"a# '$ unn"*"))a(+ ab$('). 6%. What is a chec*point and When does it occur? A C!"*5-$in' i) li5" a )na-)!$' $& '!" DBMS )'a'". B+ 'a5ing *!"*5-$in'). '!" DBMS *an ("#u*" '!" a%$un' $& 6$(5 '$ b" #$n" #u(ing (")'a(' in '!" "v"n' $& )ub)"7u"n' *(a)!").

K.Ravi

66

DBMS Lab Manual

11" ;rite a program to 3emonstrate Kt)pe an3 Kro9t)pe attrib&tes


AI(: to demonst"ate Ut pe and U"oAt pe att"ibutes

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e
Decla"e

O"acle1 ,lS0L

M PEmpno emp3empnoUt peK M PEname emp3enameUt peK M PEmp"oA empU"oAt peK No numbe"K Be+in No:R[noK Select empno1ename into m Pempno1m Pename f"om emp A!e"e empnoRnoK If7S0lU"oAcountR&: t!en DbmsPoutput3putPline7Mempno isF __ m Pempno __ Mename is M __ m Pename:K Else DbmsPoutput3putPline7 Me""o"F:K End ifK Select Y into m Pemp"oA f"om emp A!e"e empnoRnoK If7S0lU"oAcountR&: t!en DbmsPoutput3putPline7Mempno isF __ m Pemp"oA3empno __ Mename is M __ m Pemp"oA3ename:K K.Ravi 67

DBMS Lab Manual Else DbmsPoutput3putPline7 Me""o"F:K End ifK EndK 8ali3 /est Data Ente" t!e $alue fo" no: //44 1U/#U/ empno is //44 ename is $ina s3 empno is //44 ename is $ina s3 8i4a@8ice 61. What are the di))erent phases o) transaction? Di&&"("n' -!a)") a(" Anal+)i) -!a)" R"#$ <!a)" Cn#$ -!a)" 62. What do you mean 2y )lat )ile data2ase? /' i) a #a'aba)" in 6!i*! '!"(" a(" n$ -($g(a%) $( u)"( a**")) languag"). /' !a) n$ *($))4 &il" *a-abili'i") bu' i) u)"(4&(i"n#l+ an# -($vi#") u)"(4in'"(&a*" %anag"%"n'. 63. What is :transparent &!89:? /' i) $n". 6!i*! 5""-) i') <!+)i*al S'(u*'u(" !i##"n &($% u)"(. 64. !rie) theory o) Net0or*( 1ierarchical schemas and their properties 2"'6$(5 )*!"%a u)") a g(a-! #a'a )'(u*'u(" '$ $(gani?" ("*$(#) ";a%-l" &$( )u*! a #a'aba)" %anag"%"n' )+)'"% i) C CD 6!il" a !i"(a(*!i*al )*!"%a u)") a '("" #a'a )'(u*'u(" ";a%-l" &$( )u*! a )+)'"% i) /MS. 65. What is a 3uery? A 7u"(+ 6i'! (")-"*' '$ DBMS ("la'") '$ u)"( *$%%an#) '!a' a(" u)"# '$ in'"(a*' 6i'! a #a'a ba)". !" 7u"(+ languag" *an b" *la))i&i"# in'$ #a'a #"&ini'i$n languag" an# #a'a %ani-ula'i$n languag".

K.Ravi

68

DBMS Lab Manual 66. What do you mean 2y "orrelated su23uery? Sub7u"(i"). $( n")'"# 7u"(i"). a(" u)"# '$ b(ing ba*5 a )"' $& ($6) '$ b" u)"# b+ '!" -a("n' 7u"(+. D"-"n#ing $n !$6 '!" )ub7u"(+ i) 6(i''"n. i' *an b" ";"*u'"# $n*" &$( '!" -a("n' 7u"(+ $( i' *an b" ";"*u'"# $n*" &$( "a*! ($6 ("'u(n"# b+ '!" -a("n' 7u"(+. /& '!" )ub7u"(+ i) ";"*u'"# &$( "a*! ($6 $& '!" -a("n'. '!i) i) *all"# a correlated su23uery. A *$(("la'"# )ub7u"(+ *an b" "a)il+ i#"n'i&i"# i& i' *$n'ain) an+ ("&"("n*") '$ '!" -a("n' )ub7u"(+ *$lu%n) in i') >EBRB *lau)". C$lu%n) &($% '!" )ub7u"(+ *ann$' b" ("&"("n*"# an+6!"(" "l)" in '!" -a("n' 7u"(+. !" &$ll$6ing ";a%-l" #"%$n)'(a'") a n$n4*$(("la'"# )ub7u"(+. B.g. S"l"*' F 3($% CCS >!"(" G10H03H1990G /2 ,S"l"*' ADA B 3($% ARDBR >!"(" CCS .C2CM 8 ARDBR.C2CM) 67. What are the primiti;e operations common to all record mana/ement systems? A##i'i$n. #"l"'i$n an# %$#i&i*a'i$n.

K.Ravi

69

DBMS Lab Manual

15" ;rite a e<ceptions

program

to

3emonstrate

pre3e%ine3

AI(: to demonst"ate p"edefined e6ceptions

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e
Decla"e A numbe" B numbe"K C numbe"K Be+in A:R[aK B:R[bK C:Ra/bK

O"acle1 ,lS0L

DbmsPoutput3putPline7Mdi$ision is M __ C:K E6ception If 7]E@OPDI%IDE: t!en DbmsPoutput3putPline7Mb could not be #e"oF:K End ifK EndK 8ali3 /est Data0 Ente" t!e $alue fo" a: K.Ravi 70

DBMS Lab Manual &= Ente" t!e $alue fo" b: = 1U/#U/0 b could not be #e"o 8i4a@8ice0 6 . Name the 2u))er in 0hich all the commands that are typed in are stored Edit Bu&&"( 6$. What are the unary operations in <elational -l/e2ra? <RA@BC /A2 an# SBLBC /A2. 7%. -re the resultin/ relations o) +<=&>"? and 6=7N operation the same? 2$. +<=&>"?= C$n*a'"na'i$n $& "v"(+ ($6 in $n" ("la'i$n 6i'! "v"(+ ($6 in an$'!"(. 6=7N= C$n*a'"na'i$n $& ($6) &($% $n" ("la'i$n an# ("la'"# ($6) &($% an$'!"(. 71. What is <&!89 '@<N@A? 6$ i%-$('an' -i"*") $& RDBMS a(*!i'"*'u(" a(" '!" 5"(n"l. 6!i*! i) '!" )$&'6a(". an# '!" #a'a #i*'i$na(+. 6!i*! *$n)i)') $& '!" )+)'"%4l"v"l #a'a )'(u*'u(") u)"# b+ '!" 5"(n"l '$ %anag" '!" #a'aba)" 1$u %ig!' '!in5 $& an RDBMS a) an $-"(a'ing )+)'"% ,$( )"' $& )ub)+)'"%)). #")ign"# )-"*i&i*all+ &$( *$n'($lling #a'a a**"))I i') -(i%a(+ &un*'i$n) a(" )'$(ing. ("'(i"ving. an# )"*u(ing #a'a. An RDBMS %ain'ain) i') $6n li)' $& au'!$(i?"# u)"() an# '!"i( a))$*ia'"# -(ivil"g")I %anag") %"%$(+ *a*!") an# -agingI *$n'($l) l$*5ing &$( *$n*u(("n' (")$u(*" u)ag"I #i)-a'*!") an# )*!"#ul") u)"( ("7u")')I an# %anag") )-a*" u)ag" 6i'!in i') 'abl"4)-a*" )'(u*'u(") . 72. Name the su2#systems o) a <&!89 /HA. S"*u(i'+. Languag" <($*"))ing. <($*")) C$n'($l. S'$(ag" Manag"%"n'. L$gging an# R"*$v"(+. Di)'(ibu'i$n C$n'($l. (an)a*'i$n C$n'($l. M"%$(+ Manag"%"n'. L$*5 Manag"%"n' 73. Which part o) the <&!89 ta*es care o) the data dictionary? 1o0 Da'a #i*'i$na(+ i) a )"' $& 'abl") an# #a'aba)" $bj"*') '!a' i) )'$("# in a )-"*ial a("a $& '!" #a'aba)" an# %ain'ain"# ";*lu)iv"l+ b+ '!" 5"(n"l. 74. What is the 5o2 o) the in)ormation stored in data#dictionary? !" in&$(%a'i$n in '!" #a'a #i*'i$na(+ vali#a'") '!" ";i)'"n*" $& '!" $bj"*'). -($vi#") a**")) '$ '!"%. an# %a-) '!" a*'ual -!+)i*al )'$(ag" l$*a'i$n.

K.Ravi

71

DBMS Lab Manual

1C" ;rite a program to 3emonstrate &ser 3e%ine3 e<ceptions


AI(: to demonst"ate use" defined e6ceptions

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e
Decla"e A numbe" B numbe"K C numbe"K

O"acle1 ,lS0L

M di$ideP#e"o EECE,9IONK Be+in A:R[aK B:R[bK If7BR=: t!en @aise M di$ideP#e"oK else C:Ra/bK DbmsPoutput3putPline7Mdi$ision is M __ C:K End ifK E6ception If 7m di$ideP#e"o: t!en

K.Ravi

72

DBMS Lab Manual DbmsPoutput3putPline7Mb could not be #e"oF:K End ifK EndK 8ali3 /est Data0 Ente" t!e $alue fo" a: &= Ente" t!e $alue fo" b: = 1U/#U/0 b could not be #e"o 8i4a@8ice0 75. Not only <&!89 ta*es care o) locatin/ data it also #"'"(%in") an $-'i%al a**")) -a'! '$ )'$(" $( ("'(i"v" '!" #a'a 76. 1o0 do you communicate 0ith an <&!89? 1$u *$%%uni*a'" 6i'! an RDBMS u)ing S'(u*'u("# Ju"(+ Languag" ,SJL) 77. &e)ine 9BA and state the di))erences 2et0een 9BA and other con;entional pro/rammin/ Aan/ua/es SJL i) a n$n-($*"#u(al languag" '!a' i) #")ign"# )-"*i&i*all+ &$( #a'a a**")) $-"(a'i$n) $n n$(%ali?"# ("la'i$nal #a'aba)" )'(u*'u("). !" -(i%a(+ #i&&"("n*" b"'6""n SJL an# $'!"( *$nv"n'i$nal -($g(a%%ing languag") i) '!a' SJL )'a'"%"n') )-"*i&+ 6!a' #a'a $-"(a'i$n) )!$ul# b" -"(&$(%"# (a'!"( '!an !$6 '$ -"(&$(% '!"%. 7 . Name the three ma5or set o) )iles on dis* that compose a data2ase in =racle
!"(" a(" '!("" %aj$( )"') $& &il") $n #i)5 '!a' *$%-$)" a #a'aba)". All '!" &il") a(" bina(+. !")" a("

Da'aba)" &il") C$n'($l &il") R"#$ l$g) !" %$)' i%-$('an' $& '!")" a(" '!" #a'aba)" &il") 6!"(" '!" a*'ual #a'a (")i#"). !" *$n'($l &il") an# '!" ("#$ l$g) )u--$(' '!" &un*'i$ning $& '!" a(*!i'"*'u(" i')"l&.
All '!("" )"') $& &il") %u)' b" -(")"n'. $-"n. an# availabl" '$ A(a*l" &$( an+ #a'a $n '!" #a'aba)" '$ b" u)"abl". >i'!$u' '!")" &il"). +$u *ann$' a**")) '!" #a'aba)". an# '!" #a'aba)" a#%ini)'(a'$( %ig!' !av" '$ ("*$v"( )$%" $( all $& '!" #a'aba)" u)ing a ba*5u-. i& '!"(" i) $n".

K.Ravi

73

DBMS Lab Manual 7$. What is an =racle 7nstance? !" A(a*l" )+)'"% -($*"))"). al)$ 5n$6n a) A(a*l" ba*5g($un# -($*"))"). -($vi#" &un*'i$n) &$( '!" u)"( -($*"))")K&un*'i$n) '!a' 6$ul# $'!"(6i)" b" #$n" b+ '!" u)"( -($*"))") '!"%)"lv") A(a*l" #a'aba)"46i#" )+)'"% %"%$(+ i) 5n$6n a) '!" SDA. '!" system /lo2al area $( shared /lo2al area. !" #a'a an# *$n'($l )'(u*'u(") in '!" SDA a(" )!a("abl". an# all '!" A(a*l" ba*5g($un# -($*"))") an# u)"( -($*"))") *an u)" '!"%. !" *$%bina'i$n $& '!" SDA an# '!" A(a*l" ba*5g($un# -($*"))") i) 5n$6n a) an =racle instance %. What are the )our =racle system processes that must al0ays 2e up and runnin/ )or the data2ase to 2e usea2le !" &$u( A(a*l" )+)'"% -($*"))") '!a' %u)' al6a+) b" u- an# (unning &$( '!" #a'aba)" '$ b" u)"abl" in*lu#" &!W< ,Da'aba)" >(i'"(). ACW< ,L$g >(i'"(). 98=N ,S+)'"% M$ni'$(). an# +8=N ,<($*")) M$ni'$().

K.Ravi

74

DBMS Lab Manual

15" Create a C&rsor 9hich &p3ate the salaries o% an Emplo)ee as %ollo9s"


&3 if salV&===t!en update t!e sala" to &5==3 )3 if salIR&=== and V)=== t!en update t!e sala" to )5==3 (3 if salIR)=== and VR(=== t!en update t!e sala" to *===3 And also count t!e no3of "eco"ds !a$e been updated3Y/

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e

O"acle1 ,lS0L

Decla"e Cu"so" m Pcu" is select empno1sal f"om empK Eno emp3empnoUt peK Esal emp3salUt peK C numbe"K Be+in Open m Pcu"K C:R=K Loop Hetc! m Pcu" into 6no16salK If76salV&===: t!en Update emp set salR(=== A!e"e empnoR6noK C:RcG&K K.Ravi 75

DBMS Lab Manual Else if76salIR)===: and 6saV(===: t!en Update emp set salR*=== A!e"e empnoR6noK C:RcG&K End ifK End ifK E6it A!en m Pcu"UNO9HOUND End loopK Close m Pcu"K DbmaPoutput3putPline7c__F"eco"ds !a$e been successfull updatedF:K EndK S?lINa3s?lK "eco"ds !a$e been successfull updated pl/s?l p"ocedu"e successfull completed3 8ali3 /est Data Befo"e e6ecutin+ t!e cu"so"1 t!e "eco"ds in emp table as folloAs S?lIselect Y f"om empK 1U/#U/0 EM,NO ENAME 8OB MG@ CI@EDA9E SAL COMMD E,9NO K

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /(.; SMI9C /*;; ALLEN /5)& DA@D CLE@2 SALESMAN SALESMAN /;=) &/>DEC>4= /.;4 )=>HEB>4& /.;4 ))>HEB>4& SAL )=== &.== &)5= )= (== 5== (= (=

EM,NO ENAME 8OB K.Ravi

MG@ CI@EDA9E

COMM

DE,9NO 76

DBMS Lab Manual >>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /5.. 8ONES MANAGE@ /4(; =)>A,@>4& /.;4 )4>SE,>4& );/5 )= (= (=

/.5* MA@9IN SALESMAN /.;4 BLA2E L L3 L &* "oAs selected3 8i4a@8ice0 MANAGE@

&)5= &*== )45=

/4(; =&>MAJ>4&

1. What are data2ase )iles( control )iles and lo/ )iles. 1o0 many o) these )iles should a data2ase ha;e at least? Why? &ata2ase Files !" #a'aba)" &il") !$l# '!" a*'ual #a'a an# a(" '+-i*all+ '!" la(g")' in )i?". D"-"n#ing $n '!"i( )i?"). '!" 'abl") ,an# $'!"( $bj"*')) &$( all '!" u)"( a**$un') *an g$ in $n" #a'aba)" &il"Kbu' '!a'G) n$' an i#"al )i'ua'i$n b"*au)" i' #$") n$' %a5" '!" #a'aba)" )'(u*'u(" v"(+ &l";ibl" &$( *$n'($lling a**")) '$ )'$(ag" &$( #i&&"("n' u)"(). -u''ing '!" #a'aba)" $n #i&&"("n' #i)5 #(iv"). $( ba*5ing u- an# (")'$(ing ju)' -a(' $& '!" #a'aba)". You must have at least one database file but usually, more than one files are used. In terms of accessing and using the data in the tables and other objects, the number (or location) of the files is immaterial. !" #a'aba)" &il") a(" &i;"# in )i?" an# n"v"( g($6 bigg"( '!an '!" )i?" a' 6!i*! '!"+ 6"(" *("a'"# "ontrol Files !" *$n'($l &il") an# ("#$ l$g) )u--$(' '!" (")' $& '!" a(*!i'"*'u(". An+ #a'aba)" %u)' !av" a' l"a)' $n" *$n'($l &il". al'!$ug! +$u '+-i*all+ !av" %$(" '!an $n" '$ gua(# again)' l$)). !" *$n'($l &il" ("*$(#) '!" na%" $& '!" #a'aba)". '!" #a'" an# 'i%" i' 6a) *("a'"#. '!" l$*a'i$n $& '!" #a'aba)" an# ("#$ l$g). an# '!" )+n*!($ni?a'i$n in&$(%a'i$n '$ "n)u(" '!a' all '!("" )"') $& &il") a(" al6a+) in )'"-. Bv"(+ 'i%" +$u a## a n"6 #a'aba)" $( ("#$ l$g &il" '$ '!" #a'aba)". '!" in&$(%a'i$n i) ("*$(#"# in '!" *$n'($l &il").

K.Ravi

77

DBMS Lab Manual <edo Ao/s An+ #a'aba)" %u)' !av" a' l"a)' '6$ ("#$ l$g). !")" a(" '!" j$u(nal) &$( '!" #a'aba)"I '!" ("#$ l$g) ("*$(# all *!ang") '$ '!" u)"( $bj"*') $( )+)'"% $bj"*'). /& an+ '+-" $& &ailu(" $**u(). '!" *!ang") ("*$(#"# in '!" ("#$ l$g) *an b" u)"# '$ b(ing '!" #a'aba)" '$ a *$n)i)'"n' )'a'" 6i'!$u' l$)ing an+ *$%%i''"# '(an)a*'i$n). /n '!" *a)" $& n$n4#a'a l$)) &ailu(". A(a*l" *an a--l+ '!" in&$(%a'i$n in '!" ("#$ l$g) au'$%a'i*all+ 6i'!$u' in'"(v"n'i$n &($% '!" DBA. !" ("#$ l$g &il") a(" &i;"# in )i?" an# n"v"( g($6 #+na%i*all+ &($% '!" )i?" a' 6!i*! '!"+ 6"(" *("a'"#. 2. What is <=W7&? !" RA>/D i) a uni7u" #a'aba)"46i#" -!+)i*al a##(")) &$( "v"(+ ($6 $n "v"(+ 'abl". An*" a))ign"# ,6!"n '!" ($6 i) &i()' in)"('"# in'$ '!" #a'aba)"). i' n"v"( *!ang") un'il '!" ($6 i) #"l"'"# $( '!" 'abl" i) #($--"#. !" RA>/D *$n)i)') $& '!" &$ll$6ing '!("" *$%-$n"n'). '!" *$%bina'i$n $& 6!i*! uni7u"l+ i#"n'i&i") '!" -!+)i*al )'$(ag" l$*a'i$n $& '!" ($6. A(a*l" #a'aba)" &il" nu%b"(. 6!i*! *$n'ain) '!" bl$*5 6i'! '!" ($6) A(a*l" bl$*5 a##(")). 6!i*! *$n'ain) '!" ($6 !" ($6 6i'!in '!" bl$*5 ,b"*au)" "a*! bl$*5 *an !$l# %an+ ($6)) !" RA>/D i) u)"# in'"(nall+ in in#";") a) a 7ui*5 %"an) $& ("'(i"ving ($6) 6i'! a -a('i*ula( 5"+ valu". A--li*a'i$n #"v"l$-"() al)$ u)" i' in SJL )'a'"%"n') a) a 7ui*5 6a+ '$ a**")) a ($6 $n*" '!"+ 5n$6 '!" RA>/D 3. What is =racle !loc*? "an t0o =racle !loc*s ha;e the same address? A(a*l" L&$(%a')L '!" #a'aba)" &il") in'$ a nu%b"( $& A(a*l" bl$*5) 6!"n '!"+ a(" &i()' *("a'"#K%a5ing i' "a)i"( &$( '!" RDBMS )$&'6a(" '$ %anag" '!" &il") an# "a)i"( '$ ("a# #a'a in'$ '!" %"%$(+ a("a). !" bl$*5 )i?" )!$ul# b" a %ul'i-l" $& '!" $-"(a'ing )+)'"% bl$*5 )i?". R"ga(#l")) $& '!" bl$*5 )i?". '!" "n'i(" bl$*5 i) n$' availabl" &$( !$l#ing #a'aI A(a*l" 'a5") u- )$%" )-a*" '$ %anag" '!" *$n'"n') $& '!" bl$*5. !i) bl$*5 !"a#"( !a) a %ini%u% )i?". bu' i' *an g($6. !")" A(a*l" bl$*5) a(" '!" )%all")' uni' $& )'$(ag". /n*("a)ing '!" A(a*l" bl$*5 )i?" *an i%-($v" -"(&$(%an*". bu' i' )!$ul# b" #$n" $nl+ 6!"n '!" #a'aba)" i) &i()' *("a'"#. Ba*! A(a*l" bl$*5 i) nu%b"("# )"7u"n'iall+ &$( "a*! #a'aba)" &il" )'a('ing a' 1. 6$ bl$*5) *an !av" '!" )a%" bl$*5 a##(")) i& '!"+ a(" in #i&&"("n' #a'aba)" &il"). 4. What is data2ase ?ri//er? A #a'aba)" '(igg"( i) a <LHSJL bl$*5 '!a' *an #"&in"# '$ au'$%a'i*all+ ";"*u'" &$( in)"('. u-#a'". an# #"l"'" )'a'"%"n') again)' a 'abl". !" '(igg"( *an " #"&in"# '$ ";"*u'" $n*" &$( '!" "n'i(" )'a'"%"n' $( $n*" &$( "v"(+ ($6 '!a' i) in)"('"#. u-#a'"#. $( #"l"'"#. 3$( an+ $n" 'abl". '!"(" a(" '6"lv" "v"n') &$( 6!i*! +$u *an #"&in" #a'aba)" '(igg"(). A #a'aba)" '(igg"( *an *all #a'aba)" -($*"#u(") '!a' a(" al)$ 6(i''"n in <LHSJL. 5. Name t0o utilities that =racle pro;ides( 0hich are use )or 2ac*up and reco;ery. Al$ng 6i'! '!" RDBMS )$&'6a(". A(a*l" -($vi#") '6$ u'ili'i") '!a' +$u *an u)" '$ ba*5 u- an# (")'$(" '!" #a'aba)". !")" u'ili'i") a(" @.port an# 7mport.

K.Ravi

78

DBMS Lab Manual !" @.port utility #u%-) '!" #"&ini'i$n) an# #a'a &$( '!" )-"*i&i"# -a(' $& '!" #a'aba)" '$ an $-"(a'ing )+)'"% bina(+ &il". !" 7mport utility ("a#) '!" &il" -($#u*"# b+ an ";-$('. ("*("a'") '!" #"&ini'i$n) $& $bj"*'). an# in)"(') '!" #a'a /& B;-$(' an# /%-$(' a(" u)"# a) a %"an) $& ba*5ing u- an# ("*$v"(ing '!" #a'aba)". all '!" *!ang") %a#" '$ '!" #a'aba)" *ann$' b" ("*$v"("# )in*" '!" ";-$(' 6a) -"(&$(%"#. !" b")' +$u *an #$ i) ("*$v"( '!" #a'aba)" '$ '!" 'i%" 6!"n '!" ";-$(' 6a) la)' -"(&$(%"#.

K.Ravi

79

DBMS Lab Manual

1:" create a proce3&re 9hich generate all the prime n&mbers belo9 the gi4en n&mber an3 co&nt the no"o% prime n&mbers" 2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e

O"acle1 ,lS0L

C"eate o" "eplace p"ocedu"e p"imePp"oc7n IN numbe"1tot OU9 numbe": as i numbe"K c numbe"K ' numbe"K Be+in i:R&K tot:R=K A!ile7iVRn: loop ':R&K c:R=K A!ile7'VRi: loop if7mod7I1':R=: t!en

K.Ravi

80

DBMS Lab Manual c:RcG&K end ifK ':R'G&K end loopK if7cR): t!en dbmsPoutput3putPline7i:K tot:RtotG&K end ifK i:RiG&K end loopK endK / S?lIp"ocedu"e c"eated3 decla"e t numbe"K be+in p"imePp"oc7&=1t:K dbmsPoutput3putPline7Mt!e total p"ime no 3a"eF__t:K endK 8ali3 /est Data0 s?lIset se"$e"output on 1U/#U/ s?lI/ K.Ravi 81

DBMS Lab Manual ) ( 5 / 9!e total p"ime no3a"e * ,l/s?l p"ocedu"e successfull completed3 8i4a@8ice 6. Name t0o utilities that =racle pro;ides( 0hich are use )or 2ac*up and reco;ery. Al$ng 6i'! '!" RDBMS )$&'6a(". A(a*l" -($vi#") '6$ u'ili'i") '!a' +$u *an u)" '$ ba*5 u- an# (")'$(" '!" #a'aba)". !")" u'ili'i") a(" @.port an# 7mport. !" @.port utility #u%-) '!" #"&ini'i$n) an# #a'a &$( '!" )-"*i&i"# -a(' $& '!" #a'aba)" '$ an $-"(a'ing )+)'"% bina(+ &il". !" 7mport utility ("a#) '!" &il" -($#u*"# b+ an ";-$('. ("*("a'") '!" #"&ini'i$n) $& $bj"*'). an# in)"(') '!" #a'a /& B;-$(' an# /%-$(' a(" u)"# a) a %"an) $& ba*5ing u- an# ("*$v"(ing '!" #a'aba)". all '!" *!ang") %a#" '$ '!" #a'aba)" *ann$' b" ("*$v"("# )in*" '!" ";-$(' 6a) -"(&$(%"#. !" b")' +$u *an #$ i) ("*$v"( '!" #a'aba)" '$ '!" 'i%" 6!"n '!" ";-$(' 6a) la)' -"(&$(%"#. 7. What are stored#procedures? -nd 0hat are the ad;anta/es o) usin/ them. S'$("# -($*"#u(") a(" #a'aba)" $bj"*') '!a' -"(&$(% a u)"( #"&in"# $-"(a'i$n. A )'$("# -($*"#u(" *an !av" a )"' $& *$%-$un# SJL )'a'"%"n'). A )'$("# -($*"#u(" ";"*u'") '!" SJL *$%%an#) an# ("'u(n) '!" (")ul' '$ '!" *li"n'. S'$("# -($*"#u(") a(" u)"# '$ ("#u*" n"'6$(5 '(a&&i*. . ?a2les deri;ed )rom the @<& a) A(" '$'all+ unn$(%ali)"# b) A(" al6a+) in 123 *) Can b" &u('!"( #"n$(%ali)"# #) Ma+ !av" %ul'i4valu"# a''(ibu'") ,b) A(" al6a+) in 123 $. 9purious tuples may occur due to i. !ad normali4ation ii. ?heta 5oins iii. >pdatin/ ta2les )rom 5oin a) i M ii b) ii M iii *) i M iii #) ii M iii ,a) i M iii b"*au)" '!"'a j$in) a(" j$in) %a#" $n 5"+) '!a' a(" n$' -(i%a(+ 5"+). K.Ravi 82

DBMS Lab Manual $%. - ! " is a set o) attri2utes. ?he )unctional dependency is as )ollo0s -! #D ! -" #D " " #D ! a) i) in 123 b) i) in 223 *) i) in 323 #) i) in BC23 ,a) i) in 123 )in*" ,AC)N 8 9 A. B. C: !"n*" AC i) '!" -(i%a(+ 5"+. Sin*" C B i) a 3D giv"n. 6!"(" n"i'!"( C i) a K"+ n$( B i) a -(i%" a''(ibu'". '!i) i' i) n$' in 323. 3u('!"( B i) n$' &un*'i$nall+ #"-"n#"n' $n 5"+ AC '!u) i' i) n$' in 223. !u) '!" giv"n 3D) i) in 123.

K.Ravi

83

DBMS Lab Manual

1D" create a proce3&re 9hich &p3ates the salaries o% an emplo)ees as %ollo9s"


&3if salV&=== t!en update t!e sal" to &5==3 )3if salIR&=== and VR)*== t!en update t!e sala" to )5==3Y/

2;?'; re>&irements0
,"ocesso" @AM Ca"d Dis< : : : AMD At!elon B &3./ GC# )5. MB *= GB

SoftAa"e

O"acle1 ,lS0L

C"eate o" "eplace p"ocedu"e m p"oc as Cu"so" m Pcu" is select empno1sal f"om empK Eno emp3empnoUt peK Esal emp3salUt peK C numbe"K Be+in Open m Pcu"K C:R=K Loop Hetc! m Pcu" into 6no16salK If76salV&===: t!en Update emp set salR&5== A!e"e empnoR6noK C:RcG&K Else Is76salIR&=== and 6salVR)*==: t!en K.Ravi 84

DBMS Lab Manual Update emp set salR)5== A!e"e empnoR6noK C:RcG&K End ifK End ifK E6it A!en m Pcu"UNO9HOUNDK End loopK Close m Pcu"K DbmsPoutput3putPline7c__F"eco"ds !a$e been successfull updatedF:K EndK / 8ali3 /est Data0 ,"ocedu"e c"eated3 S?lIe6ec m p"ocK 1U/#U/0 @eco"ds !a$e been successfull completed3

/Y c"eate function A!ic! add tAo +i$en numbe"s3 7Simple p"o+"ams: Y/ C"eate o" "eplace function addPfun7a numbe"1b numbe": "etu"n Numbe" as C numbe"K Be+in C:RaGbK

K.Ravi

85

DBMS Lab Manual @etu"n cK EndK / Hunction c"eated3

/YaddPfun specificationY/ Decla"e @esult numbe"K Be+in @esult:RaddPfun7&=1)=:K DbmsPoutput3putPline7Mt!e sum of &= and )= isF__"esult:K EndK S?lI/ 9!e sum of &= and )= is (= ,l/s?l p"ocedu"e successfull completed3

/Yc"eate a function A!ic! count total no3of emplo ees !a$in+ sala" less t!an .===3Y/ /Yfunction bod Y/ C"eate o" "eplace function countPemp7esal numbe":"etu"n numbe" as Cu"so" $inPcu" as Select empno1sal f"om empK Eno emp3empnoUt peK Esal emp3salUt peK

K.Ravi

86

DBMS Lab Manual C numbe"K Be+in Open $inPcu"K C:R=K loop fetc! $inPcu" into 6no16salK if76salVesal: t!en c:RcG&K end ifK e6it A!en $inPcu"UnotfoundK end loopK close $inPcu"K "etu"n cK endK / Hunction c"eated3 /Yfunction specificationY/ Decla"e Ne numbe"K Esal numbe"K Be+in Ne:RcountPemp76sal:K DbmsPoutput3putPline76sal:K K.Ravi 87

DBMS Lab Manual DbmaPoutput3putPline7Mt!e"e a"e M__ne__Kemplo eesF:K EndK / 1U/#U/ 9!e"e a"e 4 emplo ees3 8i4a@8ice0 $1. 7n mappin/ o) @<& to &F& a) "n'i'i") in BRD )!$ul# *$((")-$n# '$ an ";i)'ing "n'i'+H)'$(" in D3D b) "n'i'+ in D3D i) *$nv"('"# '$ a''(ibu'") $& an "n'i'+ in BRD *) ("la'i$n) in BRD !a) 1 '$ 1 *$((")-$n#"n*" '$ -($*"))") in D3D #) ("la'i$n)!i-) in BRD !a) 1 '$ 1 *$((")-$n#"n*" '$ &l$6) in D3D ,a) "n'i'i") in BRD )!$ul# *$((")-$n# '$ an ";i)'ing "n'i'+H)'$(" in D3D $2. - dominant entity is the entity a) $n '!" 2 )i#" in a 1 = 2 ("la'i$n)!ib) $n '!" 1 )i#" in a 1 = 2 ("la'i$n)!i*) $n "i'!"( )i#" in a 1 = 1 ("la'i$n)!i#) n$'!ing '$ #$ 6i'! 1 = 1 $( 1 = 2 ("la'i$n)!i,b) $n '!" 1 )i#" in a 1 = 2 ("la'i$n)!i$3. 9elect EN=<?1E( ">9?=8@< From ">9?F&?A9 Where <@C7=N G ENE =rder !y ">9?=8@< >nion 9elect E@-9?E( ">9?=8@< From ">9?F&?A9 Where <@C7=N G E@E =rder !y ">9?=8@< !" ab$v" i) a) 2$' an "(($( b) B(($( 4 '!" )'(ing in )ingl" 7u$'") G2AR EG an# GSAC EG *) B(($( 4 '!" )'(ing )!$ul# b" in #$ubl" 7u$'") #) B(($( 4 ARDBR B1 *lau)" ,#) B(($( 4 '!" ARDBR B1 *lau)". Sin*" ARDBR B1 *lau)" *ann$' b" u)"# in C2/A2S $4. What is 9tora/e 8ana/er? /' i) a -($g(a% %$#ul" '!a' -($vi#") '!" in'"(&a*" b"'6""n '!" l$64l"v"l #a'a )'$("# in #a'aba)". a--li*a'i$n -($g(a%) an# 7u"(i") )ub%i''"# '$ '!" )+)'"%. $5. What is !u))er 8ana/er? /' i) a -($g(a% %$#ul". 6!i*! i) (")-$n)ibl" &$( &"'*!ing #a'a &($% #i)5 )'$(ag" in'$ %ain %"%$(+ an# #"*i#ing 6!a' #a'a '$ b" *a*!" in %"%$(+. K.Ravi

88

DBMS Lab Manual

$6. What is ?ransaction 8ana/er? /' i) a -($g(a% %$#ul". 6!i*! "n)u(") '!a' #a'aba)". ("%ain) in a *$n)i)'"n' )'a'" #")-i'" )+)'"% &ailu(") an# *$n*u(("n' '(an)a*'i$n ";"*u'i$n -($*""#) 6i'!$u' *$n&li*'ing. $7. What is File 8ana/er? /' i) a -($g(a% %$#ul". 6!i*! %anag") '!" all$*a'i$n $& )-a*" $n #i)5 )'$(ag" an# #a'a )'(u*'u(" u)"# '$ ("-(")"n' in&$(%a'i$n )'$("# $n a #i)5. $ . What is -uthori4ation and 7nte/rity mana/er? /' i) '!" -($g(a% %$#ul". 6!i*! '")') &$( '!" )a'i)&a*'i$n $& in'"g(i'+ *$n)'(ain' an# *!"*5) '!" au'!$(i'+ $& u)"( '$ a**")) #a'a. $$. What are stand#alone procedures? <($*"#u(") '!a' a(" n$' -a(' $& a -a*5ag" a(" 5n$6n a) )'an#4al$n" b"*au)" '!"+ in#"-"n#"n'l+ #"&in"#. A g$$# ";a%-l" $& a )'an#4al$n" -($*"#u(" i) $n" 6(i''"n in a SJLF3$(%) a--li*a'i$n. !")" '+-") $& -($*"#u(") a(" n$' availabl" &$( ("&"("n*" &($% $'!"( A(a*l" '$$l). An$'!"( li%i'a'i$n $& )'an#4al$n" -($*"#u(") i) '!a' '!"+ a(" *$%-il"# a' (un 'i%". 6!i*! )l$6) ";"*u'i$n. 1%%. What are cursors /i;e di))erent types o) cursors. <LHSJL u)") *u()$() &$( all #a'aba)" in&$(%a'i$n a**"))") )'a'"%"n'). !" languag" )u--$(') '!" u)" '6$ '+-") $& *u()$() 7mplicit @.plicit 1%1. What is cold 2ac*up and hot 2ac*up (in case o) =racle)? "old !ac*up, /' i) *$-+ing '!" '!("" )"') $& &il") ,#a'aba)" &il"). ("#$ l$g). an# *$n'($l &il") 6!"n '!" in)'an*" i) )!u' #$6n. !i) i) a )'(aig!' &il" *$-+. u)uall+ &($% '!" #i)5 #i("*'l+ '$ 'a-". 1$u %u)' )!u' #$6n '!" in)'an*" '$ gua(an'"" a *$n)i)'"n' *$-+. /& a *$l# ba*5u- i) -"(&$(%"#. '!" $nl+ $-'i$n availabl" in '!" "v"n' $& #a'a &il" l$)) i) (")'$(ing all '!" &il") &($% '!" la'")' ba*5u-. All 6$(5 -"(&$(%"# $n '!" #a'aba)" )in*" '!" la)' ba*5u- i) l$)'. 1ot !ac*up, S$%" )i'") ,)u*! a) 6$(l#6i#" ai(lin" (")"(va'i$n) )+)'"%)) *ann$' )!u' #$6n '!" #a'aba)" 6!il" %a5ing a ba*5u- *$-+ $& '!" &il"). !" *$l# ba*5u- i) n$' an availabl" $-'i$n. S$ #i&&"("n' %"an) $& ba*5ing u- #a'aba)" %u)' b" u)"# K '!" !$' ba*5u-. /))u" a SJL *$%%an# '$ in#i*a'" '$ A(a*l". $n a 'abl")-a*"4b+4'abl")-a*" ba)i). '!a' '!" &il") $& '!" 'abl")-a*" a(" '$ ba*5"# u-. !" u)"() *an *$n'inu" '$ %a5" &ull u)" $& '!" &il"). in*lu#ing %a5ing *!ang") '$ '!" #a'a. An*" '!" u)"( !a) in#i*a'"# '!a' !"H)!" 6an') '$ ba*5 u- '!" 'abl")-a*" &il"). !"H)!" *an u)" '!" $-"(a'ing )+)'"% '$ *$-+ '!$)" &il") '$ '!" #")i("# ba*5u#")'ina'i$n. !" #a'aba)" %u)' b" (unning in ARCE/OBLAD %$#" &$( '!" !$' ba*5u$-'i$n.

K.Ravi

89

DBMS Lab Manual /& a #a'a l$)) &ailu(" #$") $**u(. '!" l$)' #a'aba)" &il") *an b" (")'$("# u)ing '!" !$' ba*5u- an# '!" $nlin" an# $&&lin" ("#$ l$g) *("a'"# )in*" '!" ba*5u- 6a) #$n". !" #a'aba)" i) (")'$("# '$ '!" %$)' *$n)i)'"n' )'a'" 6i'!$u' an+ l$)) $& *$%%i''"# '(an)a*'i$n). 1%2. What are -rmstron/ rules? 1o0 do 0e say that they are complete andHor sound !" 6"ll45n$6n in&"("n*" (ul") &$( 3D) R"&l";iv" (ul" = /& 1 i) )ub)"' $( "7ual '$ 0 '!"n 0 1. Aug%"n'a'i$n (ul"= /& 0 1 '!"n 0P 1P. (an)i'iv" (ul"= /& 90 1. 1 P: '!"n 0 P. D"*$%-$)i'i$n (ul" = /& 0 1P '!"n 0 1. Cni$n $( A##i'iv" (ul"= /& 90 1. 0 P: '!"n 0 1P. <)"u#$ (an)i'iv" (ul" = /& 90 1. >1 P: '!"n >0 P. A& '!")" '!" &i()' '!("" a(" 5n$6n a) A%)'($ng Rul"). !"+ a(" )$un# b"*au)" i' i) "n$ug! i& a )"' $& 3D) )a'i)&+ '!")" '!("". !"+ a(" *all"# *$%-l"'" b"*au)" u)ing '!")" '!("" (ul") 6" *an g"n"(a'" '!" (")' all in&"("n*" (ul"). 1%3. 1o0 can you )ind the minimal *ey o) relational schema? Mini%al 5"+ i) $n" 6!i*! *an i#"n'i&+ "a*! 'u-l" $& '!" giv"n ("la'i$n )*!"%a uni7u"l+. 3$( &in#ing '!" %ini%al 5"+ i' i) ("7ui("# '$ &in# '!" *l$)u(" '!a' i) '!" )"' $& all a''(ibu'") '!a' a(" #"-"n#"n' $n an+ giv"n )"' $& a''(ibu'") un#"( '!" giv"n )"' $& &un*'i$nal #"-"n#"n*+. Algo. I D"'"(%ining 0N. *l$)u(" &$( 0. giv"n )"' $& 3D) 3 1. S"' 0N 8 0 2. S"' Al# 0N 8 0N 3. 3$( "a*! 3D 1 P in 3 an# i& 1 b"l$ng) '$ 0N '!"n a## P '$ 0N 4. R"-"a' )'"-) 2 an# 3 un'il Al# 0N 8 0N Algo.II D"'"(%ining %ini%al K &$( ("la'i$n )*!"%a R. giv"n )"' $& 3D) 3 1. S"' K '$ R '!a' i) %a5" K a )"' $& all a''(ibu'") in R 2. 3$( "a*! a''(ibu'" A in K a. C$%-u'" ,K Q A)N 6i'! (")-"*' '$ 3 b. /& ,K Q A)N 8 R '!"n )"' K 8 ,K Q A)N 1%4. What do you understand 2y dependency preser;ation? Div"n a ("la'i$n R an# a )"' $& 3D) 3. #"-"n#"n*+ -(")"(va'i$n )'a'") '!a' '!" *l$)u(" $& '!" uni$n $& '!" -($j"*'i$n $& 3 $n "a*! #"*$%-$)"# ("la'i$n Ri i) "7ual '$ '!" *l$)u(" $& 3. i.".. ,, R1,3)) C R C , Rn,3)))N 8 3N i& #"*$%-$)i'i$n i) n$' #"-"n#"n*+ -(")"(ving. '!"n )$%" #"-"n#"n*+ i) l$)' in '!" #"*$%-$)i'i$n. K.Ravi 90

DBMS Lab Manual

1%5. 6$(l# .

What is meant 2y +roacti;e( <etroacti;e and 9imultaneous >pdate. +roacti;e >pdate, !" u-#a'") '!a' a(" a--li"# '$ #a'aba)" b"&$(" i' b"*$%") "&&"*'iv" in ("al <etroacti;e >pdate, !" u-#a'") '!a' a(" a--li"# '$ #a'aba)" a&'"( i' b"*$%") "&&"*'iv" in ("al

6$(l# . 9imulatneous >pdate, !" u-#a'") '!a' a(" a--li"# '$ #a'aba)" a' '!" )a%" 'i%" 6!"n i' b"*$%") "&&"*'iv" in ("al 6$(l# . 1%6. What are the di))erent types o) 6=7N operations? @3ui 6oin, !i) i) '!" %$)' *$%%$n '+-" $& j$in 6!i*! inv$lv") $nl+ "7uali'+ *$%-a(i)i$n). !" #i)a#van'ag" in '!i) '+-" $& j$in i) '!a' '!"("

K.Ravi

91

DBMS Lab Manual

'E* E&estions0 1. Which is the su2set o) 9BA commands used to manipulate =racle &ata2ase structures( includin/ ta2les? Da'a D"&ini'i$n Languag" ,DDL) 2. What operator per)orms pattern matchin/? L/KB $-"(a'$( 3. What operator tests column )or the a2sence o) data? /S 2CLL $-"(a'$( 4. Which command e.ecutes the contents o) a speci)ied )ile? S AR S&il"na%"T $( US&il"na%"T 5. What is the parameter su2stitution sym2ol used 0ith 7N9@<? 7N?= command? M 6. Which command displays the 9BA command in the 9BA 2u))er( and then e.ecutes it? RC2 7. What are the 0ildcards used )or pattern matchin/? V &$( )ingl" *!a(a*'"( )ub)'i'u'i$n an# W &$( %ul'i4*!a(a*'"( )ub)'i'u'i$n . 9tate true or )alse. @I79?9( 9=8@( -NJ are operators in 9BA. (u" $. 9tate true or )alse. KG( LD( MG all denote the same operation. (u" 1%. What are the pri;ile/es that can 2e /ranted on a ta2le 2y a user to others? /n)"('. u-#a'". #"l"'". )"l"*'. ("&"("n*"). in#";. ";"*u'". al'"(. all 11. What command is used to /et 2ac* the pri;ile/es o))ered 2y the C<-N? command? RBOAKB 12. Which system ta2les contain in)ormation on pri;ile/es /ranted and pri;ile/es o2tained? CSBRV ABV<R/OSVMADB. CSBRV ABV<R/OSVRBCD 13. Which system ta2le contains in)ormation on constraints on all the ta2les created? CSBRVCA2S RA/2 S 14. ?<>N"-?@ ?-!A@ @8+N &@A@?@ F<=8 @8+N Will the outputs o) the a2o;e t0o commands di))er?

K.Ravi

92

DBMS Lab Manual B$'! 6ill (")ul' in #"l"'ing all '!" ($6) in '!" 'abl" BM<. 15. What is the di))erence 2et0een ?<>N"-?@ and &@A@?@ commands? RC2CA B i) a DDL *$%%an# 6!"("a) DBLB B i) a DML *$%%an#. E"n*" DBLB B $-"(a'i$n *an b" ($ll"# ba*5. bu' RC2CA B $-"(a'i$n *ann$' b" ($ll"# ba*5. >EBRB *lau)" *an b" u)"# 6i'! DBLB B an# n$' 6i'! RC2CA B. 16. What command is used to create a ta2le 2y copyin/ the structure o) another ta2le? Answer : CRBA B ABLB .. AS SBLBC *$%%an# Explanation : $ *$-+ $nl+ '!" )'(u*'u(". '!" >EBRB *lau)" $& '!" SBLBC *$%%an# )!$ul# *$n'ain a 3ALSB )'a'"%"n' a) in '!" &$ll$6ing. CRBA B ABLB 2B> ABLB AS SBLBC F 3RAM B0/S /2D ABLB >EBRB 182I /& '!" >EBRB *$n#i'i$n i) '(u". '!"n all '!" ($6) $( ($6) )a'i)&+ing '!" *$n#i'i$n 6ill b" *$-i"# '$ '!" n"6 'abl". 17. What 0ill 2e the output o) the )ollo0in/ 3uery? SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN', '**'),'*','TROUBLE') FROM DUAL; RACBLB EB RACBLB 1 . What 0ill 2e the output o) the )ollo0in/ 3uery? 9@A@"? &@"=&@(?<-N9A-?@(E-E(E1234567 $%E(E1111111111E)( E1E(EJ@9E( EN=E )N Answer : 2A Explanation : !" 7u"(+ *!"*5) 6!"'!"( a giv"n )'(ing i) a nu%"(i*al #igi'. 1$. What does the )ollo0in/ 3uery do? 9@A@"? 9-A O NPA("=88(%) F<=8 @8+N !i) #i)-la+) '!" '$'al )ala(+ $& all "%-l$+""). *$lu%n 6ill b" ("-la*"# b+ 0 an# a##"# '$ )ala(+.

!" null valu") in '!" *$%%i))i$n

2%. Which date )unction is used to )ind the di))erence 2et0een t0o dates? MA2 ESVBB >BB2 21. Why does the )ollo0in/ command /i;e a compilation error? &<=+ ?-!A@ Q?-!A@FN-8@N Oa(iabl" na%") )!$ul# )'a(' 6i'! an al-!ab"'. E"(" '!" 'abl" na%" )'a(') 6i'! an GMG )+%b$l. 22. What is the ad;anta/e o) speci)yin/ W7?1 C<-N? =+?7=N in the C<-N? command?

K.Ravi

93

DBMS Lab Manual !" -(ivil"g" ("*"iv"( *an &u('!"( g(an' '!" -(ivil"g") !"H)!" !a) $b'ain"# &($% '!" $6n"( '$ an+ $'!"( u)"(. 23. What is the use o) the &<=+ option in the -A?@< ?-!A@ command? /' i) u)"# '$ #($- *$n)'(ain') )-"*i&i"# $n '!" 'abl". 24. What is the ;alue o) RcommS and RsalS a)ter e.ecutin/ the )ollo0in/ 3uery i) the initial ;alue o) RsalS is 1%%%%? >+&-?@ @8+ 9@? 9-A G 9-A O 1%%%( "=88 G 9-AT%.1N )al 8 11000. *$%% 8 1000 25. What is the use o) &@9" in 9BA? Answer : DBSC !a) '6$ -u(-$)"). /' i) u)"# '$ #")*(ib" a )*!"%a a) 6"ll a) '$ ("'(i"v" ($6) &($% 'abl" in #")*"n#ing $(#"(. Explanation : !" 7u"(+ SBLBC F 3RAM BM< ARDBR B1 B2AMB DBSC 6ill #i)-la+ '!" $u'-u' )$('"# $n B2AMB in #")*"n#ing $(#"(. 26. What is the use o) "-9"-&@ "=N9?<-7N?9? >!"n '!i) *lau)" i) u)"# 6i'! '!" DRA< *$%%an#. a -a("n' 'abl" *an b" #($--"# "v"n 6!"n a *!il# 'abl" ";i)'). 27. Which )unction is used to )ind the lar/est inte/er less than or e3ual to a speci)ic ;alue? 3LAAR 2 . What is the output o) the )ollo0in/ 3uery? 9@A@"? ?<>N"(1234.567 (#2) F<=8 &>-AN 1200

K.Ravi

94

DBMS Lab Manual

REFERENCE'0 SCO99 U"man1 o"acle 4i>,L/S0L p"o+"ammin+19MC>)=== Lone 1 o"acle 4i>t!e complete "efe"ence19MC>)=== Lone 1 o"acle ;i>t!e complete "efe"ence19MC>)=== Ba "oss1 o"acle 9eac! Jou" Self S0L/,LS0L usin+ o"acle 4i and ;i Ait! S0L81 B,B1 )==)3 Abbe 1 o"acle 4i>A be+inne"s +uide19MC>)===3

K.Ravi

95

DBMS Lab Manual

Anne<&re @ 1

GURU NANAK Engineering College


Ib"a!impatnam1 @ @ Dist"ict - 5=& 5=. 7A3 ,3:

Assi+nment / @eco"d No > PPPPP Depa"tment of PPPPPPPPPPPPPPPPPPPPPPPP


Name Class ? Lear ? 'emester Roll No" '&bGect .ranch Date o% '&bmission 0 0 0 0 0 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ." /ech AAAAA Lear AAAAAAAAA 'emester AAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAA AAAAA ? AAAAA ? AAAAAAAAAA

AAAAAAAAAAAAAAAA 't&3ent 'ignat&re

AAAAAAAAAAAAAAAA Fac&lt) 'ignat&re

K.Ravi

96

DBMS Lab Manual

Anne<&re @ 5

In3e< #age
'" No" Date #rogram ? E<periment #age No" 'ign ? Remar=s

K.Ravi

97

DBMS Lab Manual


Anne<&re @ B

GURU NANAK Engineering College


Ib"a!impatnam1 @ @ Dist"ict - 5=& 5=. 7A3 ,3:
!'ponsore3 b)0 G&r& Nana= E3&cational 'ociet), 2)3eraba3 !A" #"$

Depa"tment of PPPPPPPPPPPPPPPPPPPPPPPP
/his is to certi%) that
Name Class ? Lear ? 'emester Roll No" '&bGect .ranch 0 0 0 0 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ." /ech AAAAAA Lear AAAAAAAA 'emester AAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAA

2as s&ccess%&ll) complete3 the co&rse o% programs ? e<periments prescribe3 b) 6a9harlal Nerh& /echnological Uni4erist) o% the 3epartment 3&ring the aca3emic )ear 500AA @ 500 AA"
AAAAAAAAAAAAAAAA Fac&lt) Incharge K.Ravi AAAAAAAAAAAAAAAA Department 2ea3 98

DBMS Lab Manual

K.Ravi

99

Anda mungkin juga menyukai