This document provides information about the DBMS lab manual for the Department of Information Technology at Valliammai Engineering College. It includes the syllabus, lab equipment, objectives, and outcomes of the course. The syllabus covers creation of databases, queries, constraints, relationships between databases, procedures, triggers and functions. The lab is equipped for 30 students with 30 PCs running front-end software like Oracle and back-end software like Oracle, MySQL or equivalent. The objectives are for students to design, populate and query databases as well as prepare reports.
This document provides information about the DBMS lab manual for the Department of Information Technology at Valliammai Engineering College. It includes the syllabus, lab equipment, objectives, and outcomes of the course. The syllabus covers creation of databases, queries, constraints, relationships between databases, procedures, triggers and functions. The lab is equipped for 30 students with 30 PCs running front-end software like Oracle and back-end software like Oracle, MySQL or equivalent. The objectives are for students to design, populate and query databases as well as prepare reports.
This document provides information about the DBMS lab manual for the Department of Information Technology at Valliammai Engineering College. It includes the syllabus, lab equipment, objectives, and outcomes of the course. The syllabus covers creation of databases, queries, constraints, relationships between databases, procedures, triggers and functions. The lab is equipped for 30 students with 30 PCs running front-end software like Oracle and back-end software like Oracle, MySQL or equivalent. The objectives are for students to design, populate and query databases as well as prepare reports.
(!!iliated t" nna #ni$ersit%, &hennai' Department of INFORMATION TECHNOLOGY DBMS LAB MANUAL Prepared by Mr.R.Senthil () *+,, Dept "! -T, ./&( Subject Code & Name: -T6302 D1MS 2a3 Year / Semester : -- 4 --- Degree & Branch : B.Tech IT (s )er nna #ni$ersit% S%lla3us #nder 2003 Regulati"ns' SYLLABUS (&"mm"n t" -n!"rmati"n Techn"l"g% 5 &"mputer Science /ngineering' 0( &reati"n "! a data3ase and 6riting S72 8ueries t" retrie$e in!"rmati"n !r"m the data3ase( 2( )er!"rming -nserti"n, Deleti"n, M"di!%ing, ltering, #pdating and .ie6ing rec"rds 3ased "n c"nditi"ns( 3( &reati"n "! .ie6s, S%n"n%ms, Se8uence, -nde9es, Sa$e p"int( :( &reating an /mpl"%ee data3ase t" set $ari"us c"nstraints( ;( &reating relati"nship 3et6een the data3ases( 6( Stud% "! )24S72 3l"ck( <( =rite a )24S72 3l"ck t" satis!% s"me c"nditi"ns 3% accepting input !r"m the user( >( =rite a )24S72 3l"ck that handles all t%pes "! e9cepti"ns( ?( &reati"n "! )r"cedures( 00( &reati"n "! data3ase triggers and !uncti"ns 00( Mini pr"@ect (pplicati"n De$el"pment using +racle4 M%s8l ' a' -n$ent"r% &"ntr"l S%stem( 3' Material Re8uirement )r"cessing( c' A"spital Management S%stem( d' Rail6a% Reser$ati"n S%stem( e' )ers"nal -n!"rmati"n S%stem( !' =e3 1ased #ser -denti!icati"n S%stem( g' Timeta3le Management S%stem( h' A"tel Management S%stem LAB EQUIPMENTS Aard6are and S"!t6are re8uired !"r a 3atch "! 30 studentsB Hardware: 30 )ers"nal &"mputers Software: Front end B .14.& CC4D. "r /8ui$alent Back end B +racle 4 S72 4 M%S724 )"st,ress 4 D12 "r /8ui$alent Platform B =ind"6s 2000 )r"!essi"nal4E) +racle ser$er c"uld 3e l"aded and can 3e c"nnected !r"m indi$idual )&s( 2 OBJECT!ES: The "t#dent "ho#ld $e made to: 2earn t" create and use a data3ase 1e !amiliariFed 6ith a 8uer% language Aa$e hands "n e9perience "n DD2 &"mmands Aa$e a g""d understanding "! DM2 &"mmands and D&2 c"mmands GamiliariFe ad$anced S72 8ueries( 1e /9p"sed t" di!!erent applicati"ns O%TCOMES: &t the end of the co#r"e' the "t#dent "ho#ld $e a$le to: Design and implement a data3ase schema !"r a gi$en pr"3lem-d"main )"pulate and 8uer% a data3ase &reate and maintain ta3les using )24S72( )repare rep"rts( REFERE(CE: sp"ken-tut"rial("rg GENERAL INSTRUCTIONS FOR LABORATORY CLASSES )O*S =ith"ut )ri"r permissi"n d" n"t enter int" the 2a3"rat"r%( =hile entering int" the 21 students sh"uld 6ear their -D cards( The Students sh"uld c"me 6ith pr"per dress c"de( Students sh"uld sign in the 2+,-N R/,-ST/R 3e!"re entering int" the la3"rat"r%( Students sh"uld c"me 6ith "3ser$ati"n, rec"rd n"te, class n"tes, and la3 rele$ant 3""k t" the la3"rat"r%( Students sh"uld maintain silence inside the la3"rat"r%( !ter c"mpleting the la3"rat"r% e9ercise, make sure t" shutd"6n the s%stem pr"perl%( )O(T*S Students 3ringing the 3ags inside the la3"rat"r%(( Students 6earing slippers insides the la3"rat"r%( Students using the c"mputers in an impr"per 6a%( Students scri33ling "n the desk and mishandling the chairs( Students using m"3ile ph"nes inside the la3"rat"r%( Students making n"ise inside the la3"rat"r%( (TRO)%CTO( TO S+, S+,B 3 Structured 8uer% language pr"n"unced as (S/7#/2'( This language is used t" c"mmunicate t" "racle data3ase( )ata$a"e Mana-ement S."tem /)BMS0B -t is a s"!t6are it helps t" manage the data3ase management s%stem sh"uld a3le t" per!"rm the !"ll"6ing acti$ities $er% easil%( 0( -nserting the ne6 data( 2( #pdating the e9iting data( 3( Deleting unnecessar% data( :( Retrie$ing the re8uire data( data3ase al"ng 6ith the s"!t6are 6hich helps t" manage( The data3ase is called data3ase management s%stem (D1MS'( D1MS 6hich is 3ased "n relati"nal the"r% is called as relati"nal data3ase management s%stem( E1am2le" of R)BMSB 0( +R&2/ 2( S72 S/R./R 3( D12 :( MHS72 ;( SH1S/ 6( T/R DT <( MS &&/SS S+, Command" The S72 language is su3di$ided acc"rding t" their !uncti"ns as !"ll"6s )), 3 )ata )efinition ,an-#a-e )M, 3 )ata Mani2#lation ,an-#a-e )R,4)+, - )ata Retrie5al ,an-#a-e 4 )ata +#er. ,an-#a-e )C,0 3 )ata Control ,an-#a-e TC,0 3 Tran"action Control )ata )efinition ,an-#a-e /)),0: 4 Data De!initi"n 2anguage (DD2' "r Schema De!initi"n 2anguage, statements are used t" de!ine the data3ase structure "r schema( CRE&TE - t" create "3@ects in the data3ase &,TER - alters the structure "! the data3ase )ROP - delete "3@ects !r"m the data3ase TR%(C&TE - rem"$e all rec"rds !r"m a ta3le, including all spaces all"cated !"r the rec"rds are rem"$ed COMME(T - add c"mments t" the data dicti"nar% RE(&ME - rename an "3@ect )ata Mani2#lation ,an-#a-e /)M,0: Data Manipulati"n 2anguage (DM2' statements are used !"r managing data 6ithin schema "3@ects( (SERT - insert data int" a ta3le %P)&TE - updates e9isting data 6ithin a ta3le )E,ETE - deletes all rec"rds !r"m a ta3le, the space !"r the rec"rds remain MER6E 3 %PSERT "perati"n (insert "r update' C&,, - call a )24S72 "r Da$a su3pr"gram E7P,&( P,&( - e9plain access path t" data ,OC8 T&B,E - c"ntr"l c"ncurrenc% )ata Retrie5al ,an-#a-e 4 )ata +#er. ,an-#a-e /)R,4)+,0: SE,ECT - retrie$e data !r"m the a data3ase )ata Control ,an-#a-e /)C,0: )ata Control ,an-#a-e (D&2' statements( S"me e9amplesB 6R&(T - gi$es userIs access pri$ileges t" data3ase RE!O8E - 6ithdra6 access pri$ileges gi$en 6ith the ,RNT c"mmand Tran"action Control /TC,0: Transacti"n &"ntr"l (T&2' statements are used t" manage the changes made 3% DM2 statements( -t all"6s statements t" 3e gr"uped t"gether int" l"gical transacti"ns( COMMT 3 sa$e 6"rk d"ne S&!EPO(T - identi!% a p"int in a transacti"n t" 6hich %"u can later r"ll 3ack RO,,B&C8 - rest"re data3ase t" "riginal since the last &+MM-T SET TR&(S&CTO( - &hange transacti"n "pti"ns like is"lati"n le$el and 6hat r"ll3ack segment t" use 5
Fiq: SQL Architecture: R#le": 0( +racle reser$ed 6"rds cann"t 3e used( 2( #ndersc"re, numerals, letters are all"6ed 3ut n"t 3lank space( 3( Ma9imum length !"r the ta3le name is 30 characters( :( T6" di!!erent ta3les sh"uld n"t ha$e same name( ;( =e sh"uld speci!% a uni8ue c"lumn name( 6( =e sh"uld speci!% pr"per data t%pe al"ng 6ith 6idth( <( =e can include Jn"t nullK c"nditi"n 6hen needed( 1% de!ault it is LnullM( >( -t is a c"mmand 3ased language( ?( -t is n"t case sensiti$e( 00( /$er% c"mmand sh"uld end 6ith LNM( 00( /$er% c"mmand starts 6ith J$er3K( 02( -t is similar t" /nglish( This language is de$el"ped in the %ear 0?<2( Mr(&+DD, 3% -1M de$el"ped 3% J-1MK( 6 WORDS TO REMEMBER This appendi9 lists 6"rds that ha$e a special meaning t" +racle( /ach 6"rd pla%s a speci!ic r"le in the c"nte9t in 6hich it appears( G"r e9ample, in an -NS/RT statement, the reser$ed 6"rd -NT+ intr"duces the ta3les t" 6hich r"6s 6ill 3e added( 1ut, in a G/T&A "r S/2/&T statement, the reser$ed 6"rd -NT+ intr"duces the "utput h"st $aria3les t" 6hich c"lumn $alues 6ill 3e assigned( Oracle Re"er5ed 9ord" The !"ll"6ing 6"rds are reser$ed 3% +racle( That is, the% ha$e a special meaning t" +racle and s" cann"t 3e rede!ined( G"r this reas"n, %"u cann"t use them t" name data3ase "3@ects such as c"lumns, ta3les, "r inde9es( &&/SS &+MM/NT G2+T -S +)T-+N STRT #N-+N DD &+M)R/SS G+R 2/./2 +R S/2/&T #N-7#/ 22 &+NN/&T GR+M 2-K/ +RD/R S/SS-+N #)DT/ 2T/R &R/T/ ,RNT 2+&K )&TGR// S/T #S/R ND &#RR/NT ,R+#) 2+N, )R-+R SAR/ .2-DT/ NH DT/ A.-N, ME/ET/NTS )R-.-2/,/S S-O/ .2#/S RRH2/N D/&-M2 -D/NT-G-/D M-N#S )#12-& SM22-NT .R&AR S D/G#2T -MM/D-T/ M+D/ R= S721#G .R&AR2 S& D/2/T/ -N N+TG+#ND R/NM/ S#&&/SSG#2 .-/= #D-T D/S& -N&R/M/NT N+=-T R/S+#R&/ SHN+NHM =A/N/./R 1/T=//N D-ST-N&T -ND/E N#22 R/.+K/ SHSDT/ =A/R/ 1H DR+) -N-T-2 N#M1/R R+= T12/ =-TA &AR /2S/ -NS/RT +G R+=-D TA/N &A/&K /E&2#S-./ -NT/,/R +GG2-N/ R+=21/2 T+ &2#ST/R /E-STS -NT/RS/&T +N R+=N#M TR-,,/R &+2#MN G-2/ -NT+ +N2-N/ R+=S #-D Oracle 8e.word" The !"ll"6ing 6"rds als" ha$e a special meaning t" +racle 3ut are n"t reser$ed 6"rds and s" can 3e rede!ined( A"6e$er, s"me might e$entuall% 3ec"me reser$ed 6"rds( DM-N &+#NT G+R/-,N M-N/ET/NTS )R/&-S-+N S72/RR+R GT/R &#RS+R G+RTRN M-N.2#/ )R-MRH S72STT/ 22+&T/ &H&2/ G+#ND M+D#2/ )R-.T/ STT/M/NTP-D N2HO/ DT1S/ G#N&T-+N M+#NT )R+&/D#R/ STT-ST-&S R&A-./ DTG-2/ ,+ N/ET )R+G-2/ ST+) R&A-./2+, D1 ,+T+ N/= 7#+T ST+R,/ #TA+R-OT-+N D/& ,R+#)S N+R&A-./2+, R/D S#M ., D/&2R/ -N&2#D-N, N+&&A/ R/2 S=-T&A 1&K#) D-S12/ -ND-&T+R N+&H&2/ R/&+./R SHST/M 1/,-N D-SM+#NT -N-TRNS N+ME.2#/ R/G/R/N&/S T12/S 1/&+M/ D+#12/ -NSTN&/ N+M-N.2#/ R/G/R/N&-N, T12/S)&/ 1/G+R/ D#M) -NT N+N/ R/S/T2+,S T/M)+RRH 12+&K /&A K/H N++RD/R R/STR-&T/D TAR/D 1+DH /N12/ 2N,#,/ N+R/S/T2+,S R/#S/ T-M/ &&A/ /ND 2H/R N+RM2 R+2/ TR&-N, &N&/2 /S&)/ 2-NK N+S+RT R+2/S TRNS&T-+N &S&D/ /./NTS 2-STS N#M/R-& R+221&K TR-,,/RS &AN,/ /E&/)T 2+,G-2/ +GG S./)+-NT TR#N&T/ &AR&T/R /E&/)T-+NS MN,/ +2D S&A/M #ND/R &A/&K)+-NT /E/& MN#2 +N2H S&N #N2-M-T/D &2+S/ /E)2-N ME +)/N S/&T-+N #NT-2 &+1+2 /E/&#T/ MEDTG-2/S +)T-M2 S/,M/NT #S/ &+MM-T /ET/NT ME-NSTN&/S +=N S/7#/N&/ #S-N, &+M)-2/ /ET/RN22H ME2+,G-2/S )&K,/ SAR/D =A/N &+NSTR-NT G/T&A ME2+,A-ST+RH )R22/2 SN)SA+T =R-T/ 7 &+NSTR-NTS G2#SA ME2+,M/M1/RS )&T-N&R/S/ S+M/ =+RK &+NT/NTS GR//2-ST METRNS )&T#S/D S+RT &+NT-N#/ GR//2-STS ME.2#/ )2N S72 &+NTR+2G-2/ G+R&/ M-N )2- S72&+D/ P,4S+, Re"er5ed 9ord" The !"ll"6ing )24S72 ke%6"rds ma% re8uire special treatment 6hen used in em3edded S72 statements( 1+RT &2#ST/R D/2/T/ A.-N, N#22 R/S+#R&/ T12/ &&/)T &2#ST/RS D/2T -D/NT-G-/D N#M1/R R/T#RN T12/S &&/SS &+2#TA D/S& -G N#M1/RP1S/ R/./RS/ TSK DD &+2#MNS D-,-TS -N +G R/.+K/ T/RM-NT/ 22 &+MM-T D-S)+S/ -ND/E +N R+221&K TA/N 2T/R &+M)R/SS D-ST-N&T -ND/E/S +)/N R+=-D T+ ND &+NN/&T D+ -ND-&T+R +)T-+N R+=21/2 TR#/ NH &+NSTNT DR+) -NS/RT +R R+=N#M TH)/ RRH &+#NT /2S/ -NT/,/R +RD/R R+=TH)/ #N-+N RRH2/N &RSA /2S-G -NT/RS/&T +TA/RS R#N #N-7#/ S &R/T/ /ND -NT+ +#T S./)+-NT #)DT/ S& &#RR/NT /NTRH -S )&K,/ S&A/M #S/ SS/RT &#RR.2 /E&/)T-+N 2/./2 )RT-T-+N S/2/&T .2#/S SS-,N &#RS+R /E&/)T-+NP-N-T 2-K/ )&TGR// S/)RT/ .R&AR T DT1S/ /E-STS 2-M-T/D )+S-T-./ S/T .R&AR2 #TA+R-OT-+N DTP1S/ /E-T 2++) )R,M S-O/ .R-N&/ ., DT/ G2S/ ME )R-+R SM22-NT .-/= 1S/PT12/ D1 G/T&A M-N )R-.T/ S)&/ .-/=S 1/,-N D/1#,+GG G2+T M-N#S )R+&/D#R/ S72 =A/N 1/T=//N D/1#,+N G+R M2S21/2 )#12-& S72&+D/ =A/R/ 1-NRHP-NT/,/R D/&2R/ G+RM M+D R-S/ S72/RRM =A-2/ 1+DH D/&-M2 GR+M M+D/ RN,/ STRT =-TA 1++2/N D/G#2T G#N&T-+N NT#R2 R/2 STT/M/NT =+RK 1H &A/&K ,/N/R-& N/= R/&+RD STDD/. E+R &S/ &2+S/ ,+T+ N/ET.2 R/2/S/ S#1TH)/ &AR D/G-N-T-+N ,RNT N+&+M)R/SS R/MR S#M &ARP1S/ D/2H ,R+#) N+T R/NM/ T1#TA Oracle Re"er5ed (ame"2ace" &"ntains a list "! namespaces that are reser$ed 3% +racle( The initial characters "! !uncti"n names in +racle li3raries are restricted t" the character strings in this list( 1ecause "! p"tential name c"n!licts, use !uncti"n names that d" n"t 3egin 6ith these characters( G"r e9ample, the S72QNet Transparent Net6"rk Ser$ice !uncti"ns all 3egin 6ith the characters RNS,R s" %"u need t" a$"id naming !uncti"ns that 3egin 6ith RNS(R (ame"2ace ,i$rar. + +&- !uncti"ns S !uncti"n names !r"m S722-1 and s%stem-dependent li3raries E e9ternal !uncti"ns !"r E applicati"ns "nl% ,/N K) 2 N N& ND N2 NM NR NS NT NO TT& #)- -nternal !uncti"ns S+, O2erator" &n "perat"r is a reser$ed 6"rd "r a character used primaril% in an S72 statementIs =A/R/ clause t" per!"rm "perati"n(s', such as c"mparis"ns and arithmetic "perati"ns( +perat"rs are used t" speci!% c"nditi"ns in an S72 statement and t" ser$e as c"n@uncti"ns !"r multiple c"nditi"ns in a statement( rithmetic "perat"rs &"mparis"n "perat"rs 8 2"gical "perat"rs +perat"rs used t" negate c"nditi"n( &rithmetic o2erator" ssume $aria3le a h"lds 00 and $aria3le 3 h"lds 20, thenB Operator Description Example + Addition - Adds values on either side of the operator a + b will give 30 - Subtraction - Subtracts right hand operand fro left hand operand a - b will give -!0 " #ultiplication - #ultiplies values on either side of the operator a " b will give $00 % &ivision - &ivides left hand operand b' right hand operand b % a will give $ ( #odulus - &ivides left hand operand b' right hand operand and returns reainder b ( a will give 0 Com2ari"on o2erator" O2erator )e"cri2tion E1am2le S &hecks i! the $alues "! t6" "perands are e8ual "r n"t, i! %es then c"nditi"n 3ec"mes true( (a S 3' is n"t true( TS &hecks i! the $alues "! t6" "perands are e8ual "r n"t, i! $alues are n"t e8ual then c"nditi"n 3ec"mes true( (a TS 3' is true( UV &hecks i! the $alues "! t6" "perands are e8ual "r n"t, i! $alues are n"t e8ual then c"nditi"n 3ec"mes true( (a UV 3' is true( V &hecks i! the $alue "! le!t "perand is greater than the $alue "! right "perand, i! %es then c"nditi"n 3ec"mes true( (a V 3' is n"t true( U &hecks i! the $alue "! le!t "perand is less than the $alue "! right "perand, i! %es then c"nditi"n 3ec"mes true( (a U 3' is true( VS &hecks i! the $alue "! le!t "perand is greater than "r e8ual t" the $alue "! right "perand, i! %es then c"nditi"n 3ec"mes true( (a VS 3' is n"t true( US &hecks i! the $alue "! le!t "perand is less than "r e8ual t" the $alue "! right "perand, i! %es then c"nditi"n 3ec"mes true( (a US 3' is true( TU &hecks i! the $alue "! le!t "perand is n"t less than the $alue "! right "perand, i! %es then c"nditi"n 3ec"mes true( (a TU 3' is !alse( TV &hecks i! the $alue "! le!t "perand is n"t greater than the $alue "! right "perand, i! %es then c"nditi"n 3ec"mes true( (a TV 3' is true( ,o-ical o2erator" O2erator )e"cri2tion 22 The 22 "perat"r is used t" c"mpare a $alue t" all $alues in an"ther $alue set( ND The ND "perat"r all"6s the e9istence "! multiple c"nditi"ns in an S72 statementIs =A/R/ clause( NH The NH "perat"r is used t" c"mpare a $alue t" an% applica3le $alue in the list acc"rding t" the c"nditi"n( 1/T=//N The 1/T=//N "perat"r is used t" search !"r $alues that are 6ithin a set "! $alues, gi$en the minimum $alue and the ma9imum $alue( /E-STS The /E-STS "perat"r is used t" search !"r the presence "! a r"6 in a speci!ied ta3le that meets certain criteria( -N The -N "perat"r is used t" c"mpare a $alue t" a list "! literal $alues that ha$e 3een speci!ied( 2-K/ The 2-K/ "perat"r is used t" c"mpare a $alue t" similar $alues using 6ildcard "perat"rs( N+T The N+T "perat"r re$erses the meaning "! the l"gical "perat"r 6ith 6hich it is used( /gB N+T /E-STS, N+T 1/T=//N, N+T -N, et +R The +R "perat"r is used t" c"m3ine multiple c"nditi"ns in an S72 statementIs =A/R/ clause( -S N#22 The N#22 "perat"r is used t" c"mpare a $alue 6ith a N#22 $alue( #N-7#/ The #N-7#/ "perat"r searches e$er% r"6 "! a speci!ied ta3le !"r uni8ueness (n" duplicates'( SQL Functions SOL has many but-n functons for performng cacuatons on data. S+, &--re-ate F#nction" S72 aggregate !uncti"ns return a single $alue, calculated !r"m $alues in a c"lumn( AVG() - Returns the average vaue COUNT() - Returns the number of rows 9 FIRST() - Returns the rst vaue LAST() - Returns the ast vaue MAX() - Returns the argest vaue MIN() - Returns the smaest vaue SUM() - Returns the sum S+, Scalar f#nction" S72 scalar !uncti"ns return a single $alue, 3ased "n the input $alue( UCASE() - Converts a ed to upper case LCASE() - Converts a ed to ower case MID() - Extract characters from a text ed LEN() - Returns the ength of a text ed ROUND() - Rounds a numerc ed to the number of decmas speced NOW() - Returns the current system date and tme FORMAT() - Formats how a ed s to be dspayed S+, Strin- F#nction" S72 string !uncti"ns are used primaril% !"r string manipulati"n( The !"ll"6ing ta3le details the imp"rtant string !uncti"nsB (ame )e"cri2tion 10 S&--(' Returns numeric $alue "! le!t-m"st character 1-N(' Returns a string representati"n "! the argument 1-TP2/N,TA(' Returns length "! argument in 3its &ARP2/N,TA(' Returns num3er "! characters in argument &AR(' Returns the character !"r each integer passed &AR&T/RP2/N,TA(' s%n"n%m !"r &ARP2/N,TA(' &+N&TP=S(' Returns c"ncatenate 6ith separat"r &+N&T(' Returns c"ncatenated string &+N.(' &"n$erts num3ers 3et6een di!!erent num3er 3ases /2T(' Returns string at inde9 num3er /E)+RTPS/T(' Returns a string such that !"r e$er% 3it set in the $alue 3its, %"u get an "n string and !"r e$er% unset 3it, %"u get an "!! string G-/2D(' Returns the inde9 (p"siti"n' "! the !irst argument in the su3se8uent arguments G-NDP-NPS/T(' Returns the inde9 p"siti"n "! the !irst argument 6ithin the sec"nd argument G+RMT(' Returns a num3er !"rmatted t" speci!ied num3er "! decimal places A/E(' Returns a string representati"n "! a he9 $alue -NS/RT(' -nserts a su3string at the speci!ied p"siti"n up t" the speci!ied num3er "! characters -NSTR(' Returns the inde9 "! the !irst "ccurrence "! su3string 2&S/(' S%n"n%m !"r 2+=/R(' 2/GT(' Returns the le!tm"st num3er "! characters as speci!ied 2/N,TA(' Returns the length "! a string in 3%tes 2+DPG-2/(' 2"ads the named !ile 2+&T/(' Returns the p"siti"n "! the !irst "ccurrence "! su3string 2+=/R(' Returns the argument in l"6ercase 2)D(' Returns the string argument, le!t-padded 6ith the speci!ied string 2TR-M(' Rem"$es leading spaces MK/PS/T(' Returns a set "! c"mma-separated strings that ha$e the c"rresp"nding 3it in 3its set M-D(' Returns a su3string starting !r"m the speci!ied p"siti"n +&T(' Returns a string representati"n "! the "ctal argument +&T/TP2/N,TA(' s%n"n%m !"r 2/N,TA(' +RD(' -! the le!tm"st character "! the argument is a multi-3%te character, returns the c"de !"r that character )+S-T-+N(' s%n"n%m !"r 2+&T/(' 7#+T/(' /scapes the argument !"r use in an S72 statement R/,/E) )attern matching using regular e9pressi"ns R/)/T(' Repeats a string the speci!ied num3er "! times R/)2&/(' Replaces "ccurrences "! a speci!ied string R/./RS/(' Re$erses the characters in a string R-,AT(' Returns the speci!ied rightm"st num3er "! characters R)D(' ppends string the speci!ied num3er "! times RTR-M(' Rem"$es trailing spaces S+#ND/E(' Returns a s"unde9 string S+#NDS 2-K/ &"mpares s"unds S)&/(' Returns a string "! the speci!ied num3er "! spaces STR&M)(' &"mpares t6" strings S#1STR-N,P-ND/E(' Returns a su3string !r"m a string 3e!"re the speci!ied num3er "! "ccurrences "! the delimiter S#1STR-N,(', S#1STR(' Returns the su3string as speci!ied TR-M(' Rem"$es leading and trailing spaces #&S/(' S%n"n%m !"r #))/R(' #NA/E(' &"n$erts each pair "! he9adecimal digits t" a character #))/R(' &"n$erts t" uppercase S+, (#meric F#nction" S72 numeric !uncti"ns are used primaril% !"r numeric manipulati"n and4"r mathematical calculati"ns( The !"ll"6ing ta3le details the numeric !uncti"nsB (ame )e"cri2tion 1S(' Returns the a3s"lute $alue "! numeric e9pressi"n( &+S(' Returns the arcc"sine "! numeric e9pressi"n( Returns N#22 i! the $alue is n"t in the range -0 t" 0( S-N(' Returns the arcsine "! numeric e9pressi"n( Returns N#22 i! $alue is n"t in the range -0 t" 0 TN(' Returns the arctangent "! numeric e9pressi"n( TN2(' Returns the arctangent "! the t6" $aria3les passed t" it( 1-TPND(' Returns the 3it6ise ND all the 3its in e9pressi"n( 11 1-TP&+#NT(' Returns the string representati"n "! the 3inar% $alue passed t" it( 1-TP+R(' Returns the 3it6ise +R "! all the 3its in the passed e9pressi"n( &/-2(' Returns the smallest integer $alue that is n"t less than passed numeric e9pressi"n &/-2-N,(' Returns the smallest integer $alue that is n"t less than passed numeric e9pressi"n &+N.(' &"n$ert numeric e9pressi"n !r"m "ne 3ase t" an"ther( &+S(' Returns the c"sine "! passed numeric e9pressi"n( The numeric e9pressi"n sh"uld 3e e9pressed in radians( &+T(' Returns the c"tangent "! passed numeric e9pressi"n( D/,R//S(' Returns numeric e9pressi"n c"n$erted !r"m radians t" degrees( /E)(' Returns the 3ase "! the natural l"garithm (e' raised t" the p"6er "! passed numeric e9pressi"n( G2++R(' Returns the largest integer $alue that is n"t greater than passed numeric e9pressi"n( G+RMT(' Returns a numeric e9pressi"n r"unded t" a num3er "! decimal places( ,R/T/ST(' Returns the largest $alue "! the input e9pressi"ns( -NT/R.2(' Takes multiple e9pressi"ns e9p0, e9p2 and e9p3 s" "n(( and returns 0 i! e9p0 is less than e9p2, returns 0 i! e9p0 is less than e9p3 and s" "n( 2/ST(' Returns the minimum-$alued input 6hen gi$en t6" "r m"re( 2+,(' Returns the natural l"garithm "! the passed numeric e9pressi"n( 2+,00(' Returns the 3ase-00 l"garithm "! the passed numeric e9pressi"n( M+D(' Returns the remainder "! "ne e9pressi"n 3% di$ing 3% an"ther e9pressi"n( +&T(' Returns the string representati"n "! the "ctal $alue "! the passed numeric e9pressi"n( Returns N#22 i! passed $alue is N#22( )-(' Returns the $alue "! pi )+=(' Returns the $alue "! "ne e9pressi"n raised t" the p"6er "! an"ther e9pressi"n )+=/R(' Returns the $alue "! "ne e9pressi"n raised t" the p"6er "! an"ther e9pressi"n RD-NS(' Returns the $alue "! passed e9pressi"n c"n$erted !r"m degrees t" radians( R+#ND(' Returns numeric e9pressi"n r"unded t" an integer( &an 3e used t" r"und an e9pressi"n t" a num3er "! decimal p"ints S-N(' Returns the sine "! numeric e9pressi"n gi$en in radians( S7RT(' Returns the n"n-negati$e s8uare r""t "! numeric e9pressi"n( STD(' Returns the standard de$iati"n "! the numeric e9pressi"n( STDD/.(' Returns the standard de$iati"n "! the numeric e9pressi"n( TN(' Returns the tangent "! numeric e9pressi"n e9pressed in radians( TR#N&T/(' Returns numeric e9p0 truncated t" e9p2 decimal places( -! e9p2 is 0, then the result 6ill ha$e n" decimal p"int( LIST OF EPERIMENTS :. Creation of a data$a"e and writin- S+, ;#erie" to retrie5e information from the data$a"e. 1.1)ata )efinition ,an-#a-e /)),0. a( &R/T/ 3( 2T/R c( DR+) d( TR#N&T/ e( R/NM/ !( &+MM/NT 1.2)ata Mani2#lation ,an-#a-e /)M,0 a( -NS/RT 3( #)DT/ c( D/2/T/ 12 d( S/2/&T <. Performin- n"ertion' )eletion' Modif.in-' <erin-' %2datin- and !iewin- record" $a"ed on condition". =. Creation of !iew"' S.non.m"' Se;#ence' nde1e"' Sa5e 2oint. =.:. m2lementation of !iew". 3(2( m2lementation of S.non.m" 3(3( m2lementation of Se;#ence 3(:( m2lementation of nde1e" 3(;( m2lementation of Sa5e 2oint. >. Creatin- an Em2lo.ee data$a"e to "et 5ario#" con"traint". (a'( )rimar% ke%, (e'(Null, (i'( Disa3le &"nstraints (3'(G"reign Ke%, W (!'( N"t null, (@'( Dr"p &"nstraints (c'( &heck, (g' ( De!ault, (d'( #ni8ue, (h'( /na3le &"nstraints, ?. Creatin- relation"hi2 $etween the data$a"e". ?.: m2lementation of "et o2eration" ?.<. m2lementation of (e"ted +#erie" 4 S#$;#erie" ?.<. m2lementation the Join O2eration" @. St#d. of P,4S+, $lock. A. 9rite a P,4S+, $lock to "ati"f. "ome condition" $. acce2tin- in2#t from the #"er. B. 9rite a P,4S+, $lock that handle" all t.2e" of e1ce2tion". C. Creation of Proced#re". :D. Creation of data$a"e tri--er" and f#nction" :D.: m2lementation of Tri--er" and it" a22lication 13 :D.< m2lementation of F#nction". ::. Mini 2roEect /&22lication )e5elo2ment #"in- Oracle4 M.";l 0 a' -n$ent"r% &"ntr"l S%stem( 3' Material Re8uirement )r"cessing( c' A"spital Management S%stem( d' Rail6a% Reser$ati"n S%stem( e' )ers"nal -n!"rmati"n S%stem( !' =e3 1ased #ser -denti!icati"n S%stem( g' Timeta3le Management S%stem( h' A"tel Management S%stem Creation of a data$a"e and writin- S+, ;#erie" to retrie5e information from the data$a"e. E1: (o: D:/:.:0 )&T& )EF(TO( ,&(6%&6E/)),0 FF : FF : FF &M: T" e9ecute the $ari"us Data De!initi"n 2anguage c"mmands in RD1MS( OBJECT!E: !ter c"mpleting the e9ercise the students can a3le t" #nderstand h"6 t" create a ta3le 6ith list "! !ields, M"di!% a r"6 using 6here clause, Dr"p a ta3le, Delete the un6anted r"6s in a ta3le( )&T& )EF(TO( ,&(6%&6E -t is used t" c"mmunicate 6ith data3ase( DD2 is used t"B 14 &reate an "3@ect lter the structure "! an "3@ect T" dr"p the "3@ect created( &,6ORTHM: Step 0B Start the pr"gram Step 2B ," t" S72( Step 3B /nter the user name and pass6"rd( Step :B &"nnect t" the data3ase( Step ;B T%pe the c"mmands !"r creating ta3les and per!"rm $ari"us "perati"ns "n the ta3les( Step 6B The "utput is displa%ed( Step <B St"p the pr"gram )), COMM&(): &R/T/ 2T/R DR+) TR#N&T/ &+MM/NT R/NM/ CRE&TE T&B,E &"nstraints are c"nditi"n !"r the data item t" 3e st"red int" a data3ase( There are t6" t%pes "! &"nstraints $iF(, &"lumn &"nstraints and Ta3le &"nstraints( T!"#$s -n relati"nal data3ase s%stems (D1S' data are represented using ta3les (relati"ns'( 8uer% issued against the D1S als" results in a ta3le( ta3le has the !"ll"6ing structureB Tuple "r rec"rd 0 Tuple "r rec"rd 2 ( ( ( Tuple "r rec"rd n ta3le is uni8uel% identi!ied 3% its name and c"nsists "! r"6s that c"ntain the st"red in!"rmati"n, each r"6 c"ntaining e9actl% "ne tuple ("r rec"rd'( ta3le can ha$e "ne "r m"re c"lumns( c"lumn is made up "! a c"lumn name and a data t%pe, and it descri3es an attri3ute "! the tuples( The structure "! a ta3le, als" called relati"n schema, thus is de!ined 3% its attri3utes( The t%pe "! 15 Col#mn : Col#mn < Col#mn n in!"rmati"n t" 3e st"red in a ta3le is de!ined 3% the data t%pes "! the attri3utes at ta3le creati"n time( +racle "!!ers the !"ll"6ing 3asic data t%pes: Sl.(o )ata T.2e )e"cri2tion : Char/n0 &haracter String ( n is the siFe "! $aria3le( Ma9imum siFe is 2;; characters( The de!ault siFe is 0 < V!%c&!%'( n) Character strng . n s the sze of the varabe = (#m$er Denes Numerc data type wth space for 40 dgt and space for sgn and decma pont > (#m$er /n0 Numerc varabe.n s the sze of the varabe ? (#m$er/n'd0 Numeric $aria3le(n is the siFe "! $aria3le and d is the siFe i! the decimal p"int @ Raw/"iGe0 Raw Bnary data of ength sze bytes .Maxmum sze s 32767 bytes. A nte-er It s same as number data type but vaues w be whoe numbers. Coumns dened wth ths format not accept decma vaues. B nte-er/n0 Speces an nteger data type of ength n. C ,on- De!ines a character data t%pe upt" 32<603%tes( +ne "ne l"ng c"lumn ma% 3e e!ined !"r ta3le( This t%pe "! c"lumn ma% n"t 3e used in su3 8ueries, =here clauses "r inde9es( :D ,on- Raw Same as 2+N, e9cept it c"ntains 3inar% data "r 3%te strings and n"t interpreted 3% )24S72 :: ,OB T.2e LOB varabes can used nterchangeaby wth LONG and LONG RAW varabes. It conssts of BFILE,BLOB,CLOB and NLOB :< BF,E It s used to store arge bnary ob|ects n operatng system es outsde the database := B,OB The 12+1 datat %pe t" st"re large 3inar% "3@ects in the data3ase, in-line "r "ut-"!-line( /$er% 12+1 $aria3le st"res a l"cat"r, 6hich p"ints t" a large 3inar% "3@ect( The siFe "! a 12+1 cann"t e9ceed !"ur giga3%tes :> C,OB The &2+1 datat%pe t" st"re large 3l"cks "! character data in the data3ase, in-line "r "ut-"!-line( 1"th !i9ed-6idth and $aria3le-6idth character sets are supp"rted( /$er% &2+1 $aria3le st"res a l"cat"r, 6hich p"ints t" a large 3l"ck "! character data( The siFe "! a &2+1 cann"t e9ceed !"ur giga3%tes :? (C,OB The N&2+1 datat%pe t" st"re large 3l"cks "! N&AR data in the data3ase, in-line "r "ut-"!-line( 1"th !i9ed-6idth and $aria3le-6idth character sets are supp"rted( /$er% N&2+1 $aria3le st"res a l"cat"r, 6hich p"ints t" a large 3l"ck "! N&AR data( The siFe "! an N&2+1 cann"t e9ceed !"ur giga3%tes( :@ )&TE The DT/ datat%pe t" st"re !i9ed-length datetimes, 6hich include the time "! da% in sec"nds since midnight( The date p"rti"n de!aults t" the !irst da% "! the current m"nthN the time p"rti"n de!aults t" midnight( The date !uncti"n SHSDT/ returns the current date and time S72 uses the terms ta3le, r"6, and c"lumn !"r relati"n, tuple, and attri3ute, respecti$el%( ta3le can ha$e up t" 2;: c"lumns 6hich ma% ha$e di!!erent "r same data t%pes and sets "! $alues (d"mains', respecti$el%( )"ssi3le d"mains are alphanumeric data (strings', num3ers and date !"rmats( Sample Data3ases used !"r illustrati"n "! S72 &"mmands is gi$en 3el"6 6ith /R Diagram and c"rresp"nding Relati"nal M"del 6ith suita3le data entered in the ta3les( Relati"n 3et6een /mpl"%ee and Department is ="rks is man% *t"-"ne ( DT1S/ !"r /M)2+H// and D/)RTM/NT /ntities EMP Ta3le gi$en 6ith sample Data EMP(O E(&ME JOB M6R HRE)&TE S&, COMM )EPT(O 16 <36? SM-TA &2/RK <?02 0<-D/&->0 >00 20 <:?? 22/N S2/SMN <6?> 20-G/1->0 0600 300 30 <;20 =RD S2/SMN <6?> 22-G/1->0 02;0 ;00 30 <;66 D+N/S MN,/R <>3? 02-)R->0 2?<; 20 <6;: MRT-N S2/SMN <6?> 2>-S/)->0 02;0 0:00 30 )EPT Ta3le gi$en 6ith Sample Data )EPT(O )(&ME ,OC 00 &&+#NT-N, N/= H+RK 20 R/S/R&A D22S 30 S2/S &A-&,+ :0 +)/RT-+NS 1+ST+N +%ERH: D: +:: =rite a 8uer% t" create a ta3le empl"%ee 6ith empn", ename, designati"n, and salar%( S.nta1: -t is used t" create a ta3le S72B &R/T/ U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V (S-O/', &+2#MN NM/(2 UDTTH)/V (S-O/' XXX'N Command: S72VCRE&TE T&B,E /M) (/M)N+ (%MBER />0'/NM/ !&RCH&R< /:D0' D/S-,NT-N !&RCH&R< /:D0'S2RH (%MBER /B' <00I Ta3le created( Con"traint" with Ta$le Creation: &"nstraints are c"nditi"n !"r the data item t" 3e st"red int" a data3ase( There are t6" t%pes "! &"nstraints $iF(, &"lumn &"nstraints and Ta3le &"nstraints( S.nta1: Y&+NSTR-NT c"nstraint nameZ [YN+TZ N#22 4 #N-7#/ 4 )R-MRH K/H\(&"lumnY,c"lumnZ((' G+R/-,N K/H (c"lumn Y, c"lumZX' 17 R/G/R/N&/S ta3le Y+N D/2/T/ &S&D/Z Y&A/&K (c"nditi"n'Z T&B,E )ESCRPTO( -t is used t" $ie6 the ta3le structure t" c"n!irm 6hether the ta3le 6as created c"rrectl%( +%ERH: D< +<: =rite a 8uer% t" displa% the c"lumn name and data t%pe "! the ta3le empl"%ee( S.nta1: This is used t" $ie6 the structure "! the ta3le( S72B D/S& UT12/ NM/VN Command: S72V D/S& /M)N (ame (#llJ T.2e 333333333333333 3333333333333333 /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D/S-,NT-N .R&AR2(00' S2RH N#M1/R(>,2' +%ERH: D= +=: =rite a 8uer% !"r create a !r"m an e9isting ta3le 6ith all the !ields S.nta1: s%nta9 !"r create a ta3le !r"m an e9isting ta3le 6ith all !ields( S72V &R/T/ T12/ UTR,/T T12/ NM/V S/2/&T Q GR+MUS+#R&/ T12/ NM/VN Command: S72V &R/T/ T12/ EMP: S S/2/&T Q GR+M EMPN Ta3le created( Command: S72V D/S& /M)0 Name Null] T%pe ---------------- -------------------------- /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D/S-,NT-N.R&AR2(00' S2RH N#M1/R(>,2' 18 +%ERH: D> +>: =rite a 8uer% !"r create a !r"m an e9isting ta3le 6ith selected !ields S.nta1: S%nta9 !"r create a !r"m an e9isting ta3le 6ith selected !ields( S72V &R/T/ T12/ UTR,/T T12/ NM/V S S/2/&T /M)N+, /NM/GR+M US+#R&/ T12/ NM/VN Command: S72V &R/T/ T12/ EMP< S S/2/&T EMP(O, E(&ME GR+M EMPN Ta3le created( Command: S72V D/S& /M)2 Name Null] T%pe ----------------- --------------------- ---- /M)N+ N#M1/R (:' /NM/ .R&AR2 (00' +%ERH: D? +?: =rite a 8uer% !"r create a ne6 ta3le !r"m an e9isting ta3le 6ith"ut an% rec"rdB S.nta1: The s%nta9 !"r create a ne6 ta3le !r"m an e9isting ta3le 6ith"ut an% rec"rd( S72V &R/T/ T12/ UTR,/T T12/ NM/V S S/2/&T Q GR+MUS+#R&/ T12/ NM/V =A/R/ UG2S/ &+ND-T-+NVN Command: S72V &R/T/ T12/ /M)3 S S/2/&T Q GR+M /M) =A/R/0V2N Ta3le created( Command: S72V D/S& /M)3N Name Null] T%pe ------------------ ----------------------- /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D/S-,NT-N.R&AR2(00' S2RH N#M1/R(>,2'N 19 &,TER K MO)FC&TO( O( T&B,E T" m"di!% structure "! an alread% e9isting ta3le t" add "ne m"re c"lumns and als" m"di!% the e9isting c"lumns( lter c"mmand is used t"B 0( dd a ne6 c"lumn( 2( M"di!% the e9isting c"lumn de!initi"n( 3( T" include "r dr"p integrit% c"nstraint( +%ERH: D@ +@: =rite a 7uer% t" lter the c"lumn /M)N+ N#M1/R (:' T+ /M)N+ N#M1/R (6'( S.nta1: The s%nta9 !"r alter 5 m"di!% "n a single c"lumn( S72 V 2T/R UT12/ NM/V M+D-GH U&+2#MN NM/VUDTTH)/V(S-O/'N Command: S72V2T/R T12/ EMP M+D-GH EMP(O N#M1/R (6'N Ta3le altered( 20 Command: S72V D/S& /M)N Name Null] T%pe ----------------- ---------------------------------- /M)N+ N#M1/R(6' /NM/ .R&AR2(00' D/S-,NT-N .R&AR2(00' S2RH N#M1/R(>,2' +%ERH: DA 7<( =rite a 7uer% t" lter the ta3le empl"%ee 6ith multiple c"lumns (/M)N+,/NM/(' S.nta1: T" alter ta3le 6ith multiple c"lumn( S72 V 2T/R UT12/ NM/V M+D-GH U&+2#MN NM/0VUDTTH)/V(S-O/', M+D-GH U&+2#MN NM/2VUDTTH)/V(S-O/'XXXX(N Command: S72V2T/R T12/ /M) M+D-GH (/M)N+ N#M1/R (<', /NM/.R&AR2(02''N Ta3le altered( Command: S72V D/S& /M)N Name Null] T%pe ----------------- ------------------------------- /M)N+ N#M1/R(<' /NM/ .R&AR2(02' D/S-,NT-N .R&AR2(00' S2RH N#M1/R(>,2'N +%ERH: DB 7>( =rite a 8uer% t" add a ne6 c"lumn in t" empl"%ee S.nta1: T" add a ne6 c"lumn( S72V 2T/R T12/ UT12/ NM/V DD (U&+2#MN NM/VUDTTH)/VUS-O/V'N Command: S72V 2T/R T12/ /M) DD 7#2-G-&T-+N .R&AR2(6'N Ta3le altered( S72V D/S& /M)N Name Null] T%pe ---------------- ------------------------ /M)N+ N#M1/R(<' /NM/ .R&AR2(02' D/S-,NT-N .R&AR2(00' S2RH N#M1/R(>,2' 7#2-G-&T-+N .R&AR2(6' 21 +%ERH: DC +C: =rite a 8uer% t" add multiple c"lumns in t" empl"%ee S.nta1: S%nta9 !"r add a ne6 c"lumn( S72V 2T/R T12/ UT12/ NM/V DD (U&+2#MN NM/0VUDTTH)/VUS-O/V, (U&+2#MN NM/2VUDT TH)/VUS-O/VX'N Command: S72V2T/R T12/ /M) DD (D+1 DT/, D+D DT/'N Ta3le altered( S72V D/S& /M)N Name Null] T%pe ----------------- -------------------------------- /M)N+ N#M1/R(<' /NM/ .R&AR2(02' D/S-,NT-N .R&AR2(00' S2RH N#M1/R(>,2' 7#2-G-&T-+N .R&AR2(6' D+1 DT/ D+D DT/ REMO!E 4 )ROP -t 6ill delete the ta3le structure pr"$ided the ta3le sh"uld 3e empt%( +%ERH: :D 700( =rite a 8uer% t" dr"p a c"lumn !r"m an e9isting ta3le empl"%ee S.nta1: s%nta9 !"r add a ne6 c"lumn( S72V 2T/R T12/ UT12/ NM/V DR+) &+2#MN U&+2#MN NM/VN Command: S72V 2T/R T12/ /M) DR+) &+2#MN D+DN Ta3le altered( S72V D/S& /M)N Name Null] T%pe ----------------- ------------------------------ /M)N+ N#M1/R(<' /NM/ .R&AR2(02' D/S-,NT-N .R&AR2(00' S2RH N#M1/R(>,2' 7#2-G-&T-+N .R&AR2(6' D+1 DT/ +%ERH: :: 700( =rite a 8uer% t" dr"p multiple c"lumns !r"m empl"%ee S.nta1:The S%nta9 !"r add a ne6 c"lumn( S72V 2T/R T12/ UT12/ NM/V DR+) U&+2#MNNM/0V,U&+2#MN NM/2V,XXX(( N 22 Command: S72V 2T/R T12/ /M) DR+) (D+1, 7#2-G-&T-+N'N Ta3le altered( S72V D/S& /M)N Name Null] T%pe ------------------ --------------------------- /M)N+ N#M1/R(<' /NM/ .R&AR2(02' D/S-,NT-N .R&AR2(00' S2RH N#M1/R(>,2' RE(&ME +%ERH: :< 700( =rite a 8uer% t" rename ta3le emp t" empl"%ee S.nta1:The S%nta9 !"r add a ne6 c"lumn( S72V 2T/R T12/ R/NM/ U+2D NM/V T+ UN/= NM/V Command: S72V 2T/R T12/ R/NM/ /M) T+ /M)2+H//N S72V D/S& /M)2+H//N Name Null] T%pe ------------------- -------------------------- /M)N+ N#M1/R(<' /NM/ .R&AR2(02' D/S-,NT-N .R&AR2(00' S2RH N#M1/R(>,2' TR%(C&TE T&B,E -! there is n" !urther use "! rec"rds st"red in a ta3le and the structure has t" 3e retained then the rec"rds al"ne can 3e deleted( S.nta1: TR#N&T/ T12/ UT12/ NM/VN E1am2le: Truncate ta3le /M)N 23 )ROP: T" rem"$e a ta3le al"ng 6ith its structure and data( S.nta1:The S%nta9 !"r add a ne6 c"lumn( S72V Dr"p ta3leUta3le nameVN Command: S72V dr"p ta3le empl"%eeN RES%,T: Thus the S72 c"mmands !"r DD2 c"mmands in RD1MS has 3een $eri!ied and e9ecuted success!ull%( )&T& M&(P%,&TO( ,&(6%&6E /)M,0 COMM&()S ( R)BMS E1: (o: :.< FF : FF : FF &M: T" e9ecute and $eri!% the DM2 c"mmands are the m"st !re8uentl% used S72 c"mmands and is used t" 8uer% and manipulate the e9isting data3ase "3@ects( )M, /)&T& M&(P%,&TO( ,&(6%&6E0 S/2/&T -NS/RT D/2/T/ #)DT/ &,6ORTHM: STEP :: Start the D1MS( STEP <: &reate the ta3le 6ith its essential attri3utes( STEP =: -nsert the rec"rd int" ta3le STEP >: #pdate the e9isting rec"rds int" the ta3le STEP ?: Delete the rec"rds in t" the ta3le STEP @: use sa$e p"int i! an% changes "ccur in an% p"rti"n "! the rec"rd t" und" its "riginal state( 24 STEP A: use r"ll3ack !"r c"mpletel% und" the rec"rds STEP B: use c"mmit !"r permanentl% sa$e the rec"rds (SERT The S72 -NS/RT -NT+ Statement is used t" add ne6 r"6s "! data t" a ta3le in the data3ase( n"ert a record from an e1i"tin- ta$le: +%ERH: D: 70( =rite a 8uer% t" insert the rec"rds in t" empl"%ee( S.nta1: s%nta9 !"r insert rec"rds in t" a ta3le S+, :L (SERT (TO MT&B,E (&MEL !&,%ESM !&,:' N!&,<*'O..0I Command: S72V-NS/RT -NT+ /M) .2#/S (000,IN,RDNI,I2/&T#R/RI,0;000'N 0 r"6 created( n"ert & Record %"in- S#$"tit#tion Method: +%ERH: D= 73( =rite a 8uer% t" insert the rec"rds in t" empl"%ee using su3stituti"n meth"d( S.nta1: s%nta9 !"r insert rec"rds int" the ta3le( S72 BV -NS/RT -NT+ UT12/ NM/V .2#/SU L5c"lumn nameM, L5c"lumn name 2M, X(('N Command: S72V -NS/RT -NT+ /M) .2#/S(5/M)N+,I5/NM/I,I5D/S-,NT-NI,I5S2RHI'N /nter $alue !"r empn"B 002 /nter $alue !"r enameB SR.NN /nter $alue !"r designatinB 2/&T#R/R 25 /nter $alue !"r salar%B 0;000 0 r"6 created( old :: -NS/RT -NT+ /M) .2#/S(5/M)N+,I5/NM/I,I5D/S-,NT-NI,I5S2RHI' new :: -NS/RT -NT+ /M) .2#/S(002,ISR.NNI,I2/&T#R/RI,I0;000I' S72V 4 /nter $alue !"r empn"B 003 /nter $alue !"r enameB )NN/RS/2.M /nter $alue !"r designatinB SST( )R+G /nter $alue !"r salar%B 20000 0 r"6 created( old :: -NS/RT -NT+ /M) .2#/S(5/M)N+,I5/NM/I,I5D/S-,NT-NI,I5S2RHI' new :: -NS/RT -NT+ /M) .2#/S(003,I)NN/RS/2.MI,ISST()R+GI,I20000I' S72V 4 /nter $alue !"r empn"B 00: /nter $alue !"r enameB &A-NN- /nter $alue !"r designatinB A+D, )R+G /nter $alue !"r salar%B :;000 0 r"6 created( old :: -NS/RT -NT+ /M) .2#/S(5/M)N+,I5/NM/I,I5D/S-,NT-NI,I5S2RHI' new :: -NS/RT -NT+ /M) .2#/S(00:,I&A-NN-I,IA+D, )R+GI,I:;000I' S72V S/2/&T Q GR+M /M)N /M)N+ /NM/ D/S-,NT-N S2RH ----------- ------------ ------------------- -------------- 000 N,RDN 2/&T#R/R 0;000 002 SR.NN 2/&T#R/R 0;000 003 )NN/RS/2.M SST( )R+G 20000 00: &A-NN- A+D, )R+G :;000 SE,ECT SE,ECT Statement is used t" !etch the data !r"m a data3ase ta3le 6hich returns data in the !"rm "! result ta3le( These result ta3les are called result-sets( )i"2la. the EMP ta$le: +%ERH: D< 26 73( =rite a 8uer% t" displa% the rec"rds !r"m empl"%ee( S.nta1: S%nta9 !"r select Rec"rds !r"m the ta3le( S+,L SE,ECT P FROM MT&B,E (&MELN Command: S72V S/2/&T Q GR+M /M)N /M)N+ /NM/ D/S-,NT-N S2RH ---------- ------------ ---------- ---------- 000 N,RDN 2/&T#R/R 0;000 %P)&TE The S72 %P)&TE 7uer% is used t" m"di!% the e9isting rec"rds in a ta3le( H"u can use 9HERE clause 6ith %P)&TE 8uer% t" update selected r"6s, "ther6ise all the r"6s 6"uld 3e a!!ected( +%ERH: D> 70( =rite a 8uer% t" update the rec"rds !r"m empl"%ee( S.nta1: s%nta9 !"r update rec"rds !r"m the ta3le( S72V #)DT/ UUT12/ NM/V S/T U&+2#MNN/VSU.2#/V =A/R/ U&+2#MN NM/SU.2#/VN Command: S72V #)DT/ /M) S/T S2RHS06000 =A/R/ /M)N+S000N 0 r"6 updated( S72V S/2/&T Q GR+M /M)N /M)N+ /NM/ D/S-,NT-N S2RH ---------- ------------ ------------------- --------------- 000 N,RDN 2/&T#R/R 06000 002 SR.NN 2/&T#R/R 0;000 003 )NN/RS/2.M SST( )R+G 20000 00: &A-NN- A+D,)R+G :;000 %2date M#lti2le Col#mn": +%ERH: D? 7;( =rite a 8uer% t" update multiple rec"rds !r"m empl"%ee( S.nta1: s%nta9 !"r update multiple rec"rds !r"m the ta3le( S72V #)DT/ UUT12/ NM/V S/T U&+2#MNN/VSU.2#/V =A/R/ U&+2#MN NM/SU.2#/VN 27 Command: S72V#)DT/ /M) S/T S2RH S 06000, D/S-,NT-NSISST( )R+GI =A/R/ /M)N+S002N 0 r"6 updated( S72V S/2/&T Q GR+M /M)N /M)N+ /NM/ D/S-,NT-N S2RH ---------- ------------ -------------------- -------------- 000 N,RDN 2/&T#R/R 06000 002 SR.NN SST( )R+G 06000 003 )NN/RS/2.M SST( )R+G 20000 00: &A-NN- A+D, )R+G :;000 )E,ETE The S+, )E,ETE 7uer% is used t" delete the e9isting rec"rds !r"m a ta3le( H"u can use 9HERE clause 6ith )E,ETE 8uer% t" delete selected r"6s, "ther6ise all the rec"rds 6"uld 3e deleted( +%ERH: D@ 7;( =rite a 8uer% t" delete rec"rds !r"m empl"%ee( S.nta1: S.nta1 for delete Record" from the ta$le: S72V D/2/T/ UT12/ NM/V =A/R/ U&+2#MN NM/VSU.2#/VN Command: S72V D/2/T/ /M) =A/R/ /M)N+S003N 0 r"6 deleted( S72V S/2/&T Q GR+M /M)N /M)N+ /NM/ D/S-,NT-N S2RH ---------- ------------ --------------------- -------------- 000 N,RDN 2/&T#R/R 06000 002 SR.NN SST( )R+G 06000 00: &A-NN- A+D, )R+G :;000 28 RES%,T: Thus the S72 c"mmands !"r DM2 has 3een $eri!ied and e9ecuted success!ull%( Performin- n"ertion' )eletion' Modif.in-' <erin-' %2datin- and !iewin- record" $a"ed on condition". E1: (o: D< FF : FF : FF &M: T" per!"rming inserti"n, deleti"n, m"di!%ing, altering, updating and $ie6ing rec"rds 3ased "n c"nditi"ns( &,6ORTHM: STEP :: Start the D1MS STEP <: &"nnect t" the data3ase (D1' STEP =: &reate the ta3le 6ith its essential attri3utes( STEP >: -nsert the rec"rd int" ta3le 3ased "n s"me c"nditi"n using =A/R/ &2#S/ STEP ?: #pdate the e9isting rec"rds int" the ta3le 3ased "n s"me c"nditi"n STEP @: Delete the rec"rds in t" the ta3le 3ased "n s"me c"nditi"n STEP A: #se c"mmit !"r permanentl% sa$e the rec"rds STEP B: St"p the pr"gram 29 )R,3)&T& RETRE!&, MP,EME(T(6 O( SE,ECT COMM&()S Command: S72V &R/T/ T12/ /M)( /M)N+ N#M1/R (:', /NM/ .R&AR2 (00', D+1 .R&AR2(20', M,R N#M1/R(:', A-R/DT/ DT/, S2 N#M1/R(>,2', D/)TN+ N#M1/R(3' 'N Ta3le created( S72V -NS/RT -NT+ /M) .2#/S(<36?,ISM-TAI,I&2/RKI,;000,I0<-D/&->0I,I>000I,200'N 0 r"6 created( S72V -NS/RT -NT+ /M) .2#/S(<:??,I22/NI,IS2/SMNI,;002,I20-G/1->0I,I3000I,300'N 0 r"6 created( S72V -NS/RT -NT+ /M) .2#/S(<;20,I=RDI,IS2/SMNI,;003,I22-G/1->0I,I;000I,;00'N 0 r"6 created( S72V -NS/RT -NT+ /M) .2#/S(<;66,ID+N/SI,IMN,/RI,;002,I02-)R->;I,I<;000I,200'N 0 r"6 created( S72V -NS/RT -NT+ /M) .2#/S(<;66,IRDI,I+=N/RI,;000,I30-)R-<;I,N#22,000'N 0 r"6 created( S72V -NS/RT -NT+ /M) .2#/S(<;66,IK#MRI,I&+/I,;002,I02-DN-><I,I;;000I,300'N 0 r"6 created( S72V -NS/RT -NT+ /M) .2#/S(<:??,IRM K#MRI,ISR(S2/SMNI,;003,I22-DN-><I,I02000(;;I,200'N 0 r"6 created( 30 S72V -NS/RT -NT+ /M) .2#/S(<;20,ISM K#MRI,ISR(S2/SMNI,;003,I22-DN-<;I,I22000I,300'N 0 r"6 created( THE SE,ECT ST&TEME(T SH(T&7 9TH &))TO(&, C,&%SES: Select Y Distinct 4 #ni8ue Z ( Qc"lumnname Y s alias\, X(Z Gr"m ta3lename Y 6here c"nditi"n Z Y ,r"up 1H gr"up P3%Pe9pressi"n Z YAa$ing gr"upPc"nditi"n Z Y+RD/R 1H [col(s)|expr|numeric_pos\ YS&^D/S&Z YN#22S G-RST^2STZZN S72V S/2/&T Q GR+M /M)N /M)N+ /NM/ D+1 M,R A-R/DT/ S2 D/)TN+ ------------ ---------------- --------------- ----------- ----------------- -------------- -------------------- <36? SM-TA &2/RK ;000 0<-D/&->0 >000 200 <:?? 22/N S2/SMN ;002 20-G/1->0 3000 300 <;20 =RD S2/SMN ;003 22-G/1->0 ;000 ;00 <;66 D+N/S MN,/R ;002 02-)R->; <;000 200 <;66 RD +=N/R ;000 30-)R-<; 000 <;66 K#MR &+/ ;002 02-DN->< ;;000 300 <:?? RM K#MR SR(S2/SMN ;003 22-DN->< 02000(;; 200 <;20 SM K#MR SR(S2/SMN ;003 22-DN-<; 22000 300 > r"6s selected( BH %S(6 SE,ECTE) CO,%(MS S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M)N /M)N+ /NM/ D+1 S2 ----------- ----------- ----------- -------------- <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <;66 D+N/S MN,/R <;000 <;66 RD +=N/R <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 > r"6s selected( S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2S;000N /M)N+ /NM/ D+1 S2 --------- ---------- -------------------- ---------- <;20 =RD S2/SMN ;000 31 BH %S(6 BET9EE( 4 (OT 4 ( 4 (%,, 4 ,8E BETWEEN S*nt!+: S/2/&T column_name(s) GR+M table_name =A/R/ column_name 1/T=//N value1 ND value2; S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2 BET9EE( 00000 ND 30000N /M)N+ /NM/ D+1 S2 ---------- ------------------- ------------- ------------- <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2 (OT BET9EE( 00000 &() 30000N /M)N+ /NM/ D+1 S2 ----------- ---------------- ------------ ------------ <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <;66 D+N/S MN,/R <;000 <;66 K#MR &+/ ;;000 IN S*nt!+ SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...); S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2 ( (0000(;,<;000'N /M)N+ /NM/ D+1 S2 ---------- ---------- ----------- ------- <;66 D+N/S MN,/R <;000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2 (OT ( (0000(;,<;000'N /M)N+ /NM/ D+1 S2 ---------- ---------- -------------------- ---------- <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 6 r"6s selected( S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2 S (%,,N /M)N+ /NM/ D+1 S2 ----------- ---------- ------------- --------- <;66 RD +=N/R S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2 S (OT (%,,N /M)N+ /NM/ D+1 S2 32 ---------- ---------- ------------ --------- <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <;66 D+N/S MN,/R <;000 <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 < r"6s selected( ,8E S.nta1: S/2/&T column_name(s) GR+M table_name =A/R/ column_name 2-K/ patternN S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2 ,8E ;;000N /M)N+ /NM/ D+1 S2 ---------- ---------- ---------------- ---------- <;66 K#MR &+/ ;;000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QSRQI /M)N+ /NM/ D+1 S2 ---------- ---------- -------------------- ---------- <36? SM-TA &2/RK >000 <;20 SM K#MR SR(S2/SMN 22000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QRRQI /M)N+ /NM/ D+1 S2 --------- ----------- ---------- -------------- <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QR%RQI /M)N+ /NM/ D+1 S2 ---------- --------- - ---------------- ---------- <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QR&RQI /M)N+ /NM/ D+1 S2 ----------- ----------- ------------- ---------- <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <;66 RD +=N/R <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 6 r"6s selected( S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QR,,RQI /M)N+ /NM/ D+1 S2 ---------- ------------ --------------- ------------ <:?? 22/N S2/SMN 3000 33 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QRERQI /M)N+ /NM/ D+1 S2 ---------- -- -------- ---- ------------- ---------- <:?? 22/N S2/SMN 3000 <;66 D+N/S MN,/R <;000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QR%R&RQI /M)N+ /NM/ D+1 S2 ---------- ---------- - ------------------- ---------- <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QRFFFQI 44=F /M)N+ /NM/ D+1 S2 ---------- ---------- ----------- ---------- <;66 RD +=N/R S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QRFJFQI /M)N+ /NM/ D+1 S2 ---------- ---------- ----------- -------- <;66 RD +=N/R S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QFMRQI /M)N+ /NM/ D+1 S2 ------------ ------------ --------------- -------- <36? SM-TA &2/RK >000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QFMQI n" r"6s selected S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E QFFFFRQI 44 >F /M)N+ /NM/ D+1 S2 ---------- ---------- -------------- ---------- <;66 K#MR &+/ ;;000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ ,8E Q8FFFRQI 44 =F /M)N+ /NM/ D+1 S2 ---------- ---------- ----------- --------- ---------- <;66 K#MR &+/ ;;000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ /NM/ N+T ,8E QRFJFQI /M)N+ /NM/ D+1 S2 ----------- ----------- --------------- ---------- 34 <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <;66 D+N/S MN,/R <;000 <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 < r"6s selected( RE,&TO(&, OPER&TOR S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2S;;000N /M)N+ /NM/ D+1 S2 ---------- ---------- -------------------- ---------- <;66 K#MR &+/ ;;000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2TS;;000N /M)N+ /NM/ D+1 S2 ---------- ---------- -------------------- ---------- <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <;66 D+N/S MN,/R <;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 6 r"6s selected( S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2UV;;000N /M)N+ /NM/ D+1 S2 ---------- ---------- -------------------- ---------- <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <;66 D+N/S MN,/R <;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 6 r"6s selected( S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2V;;000N /M)N+ /NM/ D+1 S2 ---------- ---------- ------------------- ---------- <;66 D+N/S MN,/R <;000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2U;;000N /M)N+ /NM/ D+1 S2 ----------- ---------- -------------------- ---------- <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2US;;000N /M)N+ /NM/ D+1 S2 ---------- ------------ -------------------- ---------- <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 35 <;66 K#MR &+/ ;;000 <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 6 r"6s selected( S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2VS;;000N /M)N+ /NM/ D+1 S2 ------------ ---------- ----------------- --------- <;66 D+N/S MN,/R <;000 <;66 K#MR &+/ ;;000 &() 4 OR S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ D+1SISR(S2/SMNI &() S2S22000N /M)N+ /NM/ D+1 S2 ----------- ------------ ------------------ ---------- <;20 SM K#MR SR(S2/SMN 22000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ D+1SISR(S2/SMNI OR S2S22000N /M)N+ /NM/ D+1 S2 ---------- ---------- -------------------- ---------- <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ S2S;000 &() (D+1SISR(S2/SMNI OR D+1SIS2/SMNI'N /M)N+ /NM/ D+1 S2 ---------- ---------- -------------------- ---------- <;20 =RD S2/SMN ;000 OR)ER BH S.nta1: S/2/&T column_name,column_name GR+M table_name +RD/R 1H column_name,column_name S&^D/S&N S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) OR)ER BH E(&MEN /M)N+ /NM/ D+1 S2 ------------ ------------ -------------------- ---------- <:?? 22/N S2/SMN 3000 <;66 D+N/S MN,/R <;000 <;66 K#MR &+/ ;;000 <;66 RD +=N/R <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 <36? SM-TA &2/RK >000 <;20 =RD S2/SMN ;000 > r"6s selected( S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) +RD/R 1H /NM/ )ESCI /M)N+ /NM/ D+1 S2 ----------- ------------ -------------------- ---------- <;20 =RD S2/SMN ;000 <36? SM-TA &2/RK >000 36 <;20 SM K#MR SR(S2/SMN 22000 <:?? RM K#MR SR(S2/SMN 02000(;; <;66 RD +=N/R <;66 K#MR &+/ ;;000 <;66 D+N/S MN,/R <;000 <:?? 22/N S2/SMN 3000 > r"6s selected( S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) +RD/R 1H /NM/ &SCI /M)N+ /NM/ D+1 S2 ----------- ------------ -------------------- ---------- <:?? 22/N S2/SMN 3000 <;66 D+N/S MN,/R <;000 <;66 K#MR &+/ ;;000 <;66 RD +=N/R <:?? RM K#MR SR(S2/SMN 02000(;; <;20 SM K#MR SR(S2/SMN 22000 <36? SM-TA &2/RK >000 <;20 =RD S2/SMN ;000 > r"6s selected( TOP 44 TOP clause is n"t in "racle instead "! that RO9(%M S.nta1 S/2/&T column_name(s) GR+M table_name =A/R/ R+=N#M US numberN S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ RO9(%M M>I /M)N+ /NM/ D+1 S2 ------------ ---------- -------------------- ---------- <36? SM-TA &2/RK >000 <:?? 22/N S2/SMN 3000 <;20 =RD S2/SMN ;000 S72V S/2/&T /M)N+,/NM/,D+1,S2 GR+M /M) =A/R/ RO9(%M M> OR)ER BH E(&MEI /M)N+ /NM/ D+1 S2 ----------- ---------- ------------------ ---------- <:?? 22/N S2/SMN 3000 <36? SM-TA &2/RK >000 <;20 =RD S2/SMN ;000 DISTINCT S*nt!+: SELECT DISTINCT coumn_name,coumn_name FROM table_name; E1: S72V S/2/&T )ST(CT D+1 GR+M /M)N D+1 37 -------------------- &2/RK S2/SMN SR(S2/SMN MN,/R &+/ +=N/R 6 r"6s selected( %S(6 &,TER This can 3e used t" add "r rem"$e c"lumns and t" m"di!% the precisi"n "! the datat%pe( a0 &))(6 CO,%M( S.nta1: alter ta3le Utable_nameV add Ucol datatypeVN E1: S72V D/S& /M)N Name Null] T%pe ------------------------- ----------- --------------------------- /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D+1 .R&AR2(20' M,R N#M1/R(:' A-R/DT/ DT/ S2 N#M1/R(>,2' D/)TN+ N#M1/R(3' S72V alter ta3le /M) add TE num3erN Ta3le altered( S72V D/S& /M)N Name Null] T%pe ----------------------------------------- ------------------------ /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D+1 .R&AR2(20' M,R N#M1/R(:' A-R/DT/ DT/ S2 N#M1/R(>,2' D/)TN+ N#M1/R(3' TE N#M1/R $0 REMO!(6 CO,%M( S.nta1: alter ta3le Utable_nameV dr"p Ucol datatypeVN E1: S72V alter ta3le /M) dr"p c"lumn TEN Ta3le altered( S72V D/S& /M)N Name Null] T%pe ------------------------ ----------------- ---------------------------- 38 /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D+1 .R&AR2(20' M,R N#M1/R(:' A-R/DT/ DT/ S2 N#M1/R(>,2' D/)TN+ N#M1/R(3' c0 (CRE&S(6 OR )ECRE&S(6 PRECSO( OF & CO,%M( S.nta1: alter ta3le Utable_nameV m"di!% Ucol datatypeVN E1: S72V alter ta3le /M) m"di!% D/)TN+ num3er(;'N Ta3le altered( S72V D/S& /M)N Name Null] T%pe ------------------------------- -------- ---------------------------- /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D+1 .R&AR2(20' M,R N#M1/R(:' A-R/DT/ DT/ S2 N#M1/R(>,2' D/)TN+ N#M1/R(;' Q T" decrease precisi"n the c"lumn sh"uld 3e empt%( d0 M&8(6 CO,%M( %(%SE) S.nta1: alter ta3le Utable_nameV set unused c"lumn UcolVN E1: S72V alter ta3le /M) set unused c"lumn D/)TN+N Ta3le altered( S72V D/S& /M)N Name Null] T%pe ------------------------ ----------------- -------------------------- /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D+1 .R&AR2(20' M,R N#M1/R(:' A-R/DT/ DT/ S2 N#M1/R(>,2' S72V S/2/&T Q GR+M /M)N /M)N+ /NM/ D+1 M,R A-R/DT/ S2 ---------- ---------- -------------------- ---------- --------- ---------- <36? SM-TA &2/RK ;000 0<-D/&->0 >000 <:?? 22/N S2/SMN ;002 20-G/1->0 3000 <;20 =RD S2/SMN ;003 22-G/1->0 ;000 39 ? r"6s selected( /$en th"ugh the c"lumn is unused still it 6ill "ccup% mem"r%( d0 )ROPP(6 %(%SE) CO,%M(S S.nta1: alter ta3le Utable_nameV dr"p unused c"lumnsN E1: S72V alter ta3le /M) dr"p unused c"lumnsN Ta3le altered( Q H"u can n"t dr"p indi$idual unused c"lumns "! a ta3le( e0 RE(&M(6 CO,%M( S.nta1: alter ta3le Utable_nameV rename c"lumn Uold_col_nameV t" Unew_col_nameVN E1: S72V alter ta3le /M) rename c"lumn S2 t" S2RHN Ta3le altered( S72V D/S& /M)N Name Null] T%pe --------------------- ------ ---------------------------- /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D+1 .R&AR2(20' M,R N#M1/R(:' A-R/DT/ DT/ S2RH N#M1/R(>,2' (SERT Method : 6E(ER&, (SERT COMM&(): S72V -NS/RT -NT+ /M)(/M)N+,/NM/,D+1,M,R,A-R/DT/,S2RH' .2#/S(0000,IRM#I,IS2/SMNI,;063,I02-DN-><I,I;6:3(;;I'N 0 r"6 created( Method < 9THO%T SPECFH THE CO,%M(S )ET&,S S72V -NS/RT -NT+ /mp .2#/S(0000,IRM#I,IS2/SMNI,;063,I02-DN-><I,I;6:3(;;I'N 0 r"6 created( Method = (SERT(6 )&T& (TO SPECFE) CO,%M(S S72V -NS/RT -NT+ /M)(/M)N+,/NM/,D+1' .2#/S(0000,IRM#I,IS2/SMNI'N 0 r"6 created( Method > BH CH&(6E THE OR)ER OF CO,%M(S 40 S72V -NS/RT -NT+ /M)(salar%,/M)N+,/NM/,D+1' .2#/S(3;000,0000,IRM#I,IS2/SMNI'N 0 r"6 created( S72V select Q !r"m empN /M)N+ /NM/ D+1 M,R A-R/DT/ S2RH ---------- ---------- --------------- -------- -------------- ---------- <36? SM-TA &2/RK ;000 0<-D/&->0 >000 <:?? 22/N S2/SMN ;002 20-G/1->0 3000 <;20 =RD S2/SMN ;003 22-G/1->0 ;000 <;66 D+N/S MN,/R ;002 02-)R->; <;000 <;66 RD +=N/R ;000 30-)R-<; <;66 K#MR &+/ ;002 02-DN->< ;;000 <:?? RM K#MR SR(S2/SMN ;003 22-DN->< 02000(;; <;20 SM K#MR SR(S2/SMN ;003 22-DN-<; 22000 <;20 SM K#MR SR(S2/SMN ;003 22-DN-<; 22000 0000 RM# S2/SMN ;063 02-DN->< ;6:3(;; 0000 RM# S2/SMN ;063 02-DN->< ;6:3(;; 0000 RM# S2/SMN 0000 RM# S2/SMN 3;000 03 r"6s selected( Method ? (SERT 9TH SE,ECT #sing this 6e can insert e9isting ta3le data t" an"ther ta3le in a single trip( 1ut the ta3le structure sh"uld 3e same( S.nta1: -nsert int" Utable1V select Q !r"m Utable2VN E1: S72V D/S& /M) Name Null] T%pe ------------------- ---------------------- ---------------------------- /M)N+ N#M1/R(:' /NM/ .R&AR2(00' D+1 .R&AR2(20' M,R N#M1/R(:' A-R/DT/ DT/ S2RH N#M1/R(>,2' S72V create ta3le /M)2+H//(/M)PN+,/M)PNM/,/M)PD+1,AR,A-R/DT/,S2RH' as select Q !r"m /M) 6here 0 S 2N Ta3le created( S72V D/S& /M)2+H// Name Null] T%pe ----------------- ----------------- ------------------------- /M)PN+ N#M1/R(:' /M)PNM/ .R&AR2(00' /M)PD+1 .R&AR2(20' AR N#M1/R(:' A-R/DT/ DT/ S2RH N#M1/R(>,2' S72V S/2/&T Q GR+M /M)2+H//N n" r"6s selected 41 S72V insert int" /M)2+H// select Q !r"m /M)N 03 r"6s created( S72V S/2/&T Q GR+M /M)2+H//N /M)PN+ /M)PNM/ /M)PD+1 AR A-R/DT/ S2RH ---------- ---------------- -------------------- -------- ---------------- ---------- <36? SM-TA &2/RK ;000 0<-D/&->0 >000 <:?? 22/N S2/SMN ;002 20-G/1->0 3000 <;20 =RD S2/SMN ;003 22-G/1->0 ;000 <;66 D+N/S MN,/R ;002 02-)R->; <;000 <;66 RD +=N/R ;000 30-)R-<; <;66 K#MR &+/ ;002 02-DN->< ;;000 <:?? RM K#MR SR(S2/SMN ;003 22-DN->< 02000(;; <;20 SM K#MR SR(S2/SMN ;003 22-DN-<; 22000 <;20 SM K#MR SR(S2/SMN ;003 22-DN-<; 22000 0000 RM# S2/SMN ;063 02-DN->< ;6:3(;; 0000 RM# S2/SMN ;063 02-DN->< ;6:3(;; 0000 RM# S2/SMN 0000 RM# S2/SMN 3;000 03 r"6s selected( Method @ M%,TB,E (SERTS =e ha$e ta3le called D/)T 6ith the !"ll"6ing c"lumns and data S72V select Q !r"m D/)TN D/)TN+ DNM/ 2+& ----------- ---------- ------- 00 acc"unting ne6 %"rk 20 research dallas 30 sales &hicag" :0 "perati"ns 3"st"n CRE&TE ST%)E(T T&B,E S72V &reate ta3le student(n" num3er(2',name $archar(2',marks num3er(3''N $0 M%,T (SERT 9TH &,, FE,)S S72V -nsert all -nt" student $alues(0,MaM,000' -nt" student $alues(2,M3M,200' -nt" student $alues(3,McM,300' Select Q!r"m dept 6here deptn"S00N 3 r"6s created( S72V Select Q !r"m studentN N+ NM/ MRKS ------- -------- ---------- 0 a 000 2 3 200 3 c 300 42 c0 M%,T (SERT 9TH SPECFE) FE,)S S72V insert all -nt" student (n",name' $alues(:,MdM' -nt" student(name,marks' $alues(MeM,:00' -nt" student $alues(3,McM,300' Select Q!r"m dept 6here deptn"S00N 3 r"6s created( S72V Select Q !r"m studentN N+ NM/ MRKS ------ -------- --------- 0 a 000 2 3 200 3 c 300 : d e :00 3 c 300 6 r"6s selected( d0 M%,T (SERT 9TH )%P,C&TE RO9S S72V insert all -nt" student $alues(0,MaM,000' -nt" student $alues(2,M3M,200' -nt" student $alues(3,McM,300' Select Q!r"m dept 6here deptn" V 00N ? r"6s created( -- This inserts ? r"6s 3ecause in the select statement retrie$es 3 rec"rds (3 inserts !"r each r"6 retrie$ed' S72V Select Q !r"m studentN N+ NM/ MRKS ------ ---- -- --------- 0 a 000 2 3 200 3 c 300 : d e :00 3 c 300 0 a 000 0 a 000 0 a 000 2 3 200 2 3 200 2 3 200 3 c 300 3 c 300 3 c 300 0; r"6s selected( 43 e0 M%,T (SERT 9TH CO()TO(S B&SE) S72V create ta3le m%t3l0(name $archar2(20',n" num3er(00''N Ta$le created. S72V insert int" m%t3l0 $alues(IramI,000'N : row created. S72V insert int" m%t3l0 $alues(IsamI,222'N : row created. S72V insert int" m%t3l0 $alues(ItamI,333'N : row created. S72V select Q !r"m m%t3l0N (&ME (O 33333333333333333333 3333333333 ram ::: "am <<< tam === S72V create ta3le %"urt3l0(name $archar2(20',n" num3er(00''N Ta$le created. S72V create ta3le %"urt3l2(name $archar2(20',n" num3er(00''N Ta$le created. S72V create ta3le %"urt3l3(name $archar2(20',n" num3er(00''N Ta$le created( S72V select Q !r"m %"urt3l0N no row" "elected S72V select Q !r"m %"urt3l2N no row" "elected S72V select Q !r"m %"urt3l3N no row" "elected S72V insert all 6hen n" V 000 then int" %"urt3l0 $alues(IramuI,0000' 6hen name S IsamI then int" %"urt3l2 $alues(IsamuI,2222' 6hen name S ItamI then int" %"urt3l3 $alues(ItamuI,3333' select Q !r"m m%t3l0 6here n" V 000N > row" created. S72V select Q !r"m m%t3l0N (&ME (O 33333333333333333333 3333333333 ram ::: "am <<< tam === 44 S72V select Q !r"m %"urt3l0N (&ME (O 33333333333333333333 3333333333 ram# :::: ram# :::: S72V select Q !r"m %"urt3l2N (&ME (O 33333333333333333333 3333333333 "am# <<<< S72V select Q !r"m %"urt3l3N (&ME (O 33333333333333333333 3333333333 tam# ==== -- This inserts : r"6s 3ecause the !irst c"nditi"n satis!ied 3 times, sec"nd c"nditi"n satis!ied "nce and the last n"ne( f0 M%,T (SERT 9TH CO()TO(S B&SE) &() E,SE 45 S72V create ta3le m%t3l0(name $archar2(20',n" num3er(00''N Ta3le created( S72V insert int" m%t3l0 $alues(IramI,000'N 0 r"6 created( S72V insert int" m%t3l0 $alues(IsamI,222'N 0 r"6 created( S72V insert int" m%t3l0 $alues(ItamI,333'N 0 r"6 created( S72V select Q !r"m m%t3l0N NM/ N+ -------------------- ---------- ram 000 sam 222 tam 333 S72V create ta3le %"urt3l0(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l2(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l3(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l:(name $archar2(20',n" num3er(00''N Ta3le created( S72V insert all 6hen n" V 000 then int" %"urt3l0 $alues(IramuI,0000' 6hen name S IsamI then int" %"urt3l2 $alues(IsamuI,2222' 6hen name S ItamI then int" %"urt3l3 $alues(ItamuI,3333' else int" %"urt3l: $alues(Ich"ttaI,::::' select Q !r"m m%t3l0 6here n" V 000N > row" created. S72V select Q !r"m %"urt3l0N NM/ N+ -------------------- ---------- ramu 0000 ramu 0000 S72V select Q !r"m %"urt3l2N NM/ N+ -------------------- ---------- samu 2222 S72V select Q !r"m %"urt3l3N NM/ N+ -------------------- ---------- tamu 3333 -0 M%,T (SERT 9TH CO()TO(S B&SE) &() FRST 46 S72V create ta3le m%t3l0(name $archar2(20',n" num3er(00''N Ta3le created( S72V insert int" m%t3l0 $alues(IramI,000'N 0 r"6 created( S72V insert int" m%t3l0 $alues(IsamI,222'N 0 r"6 created( S72V insert int" m%t3l0 $alues(ItamI,333'N 0 r"6 created( S72V create ta3le %"urt3l0(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l2(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l3(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l:(name $archar2(20',n" num3er(00''N Ta3le created( S72V select Q !r"m m%t3l0N NM/ N+ -------------------- ---------- ram 000 sam 222 tam 333 S72V insert !irst 6hen n"S000 then int" %"urt3l0 $alues(IramuI,0000' 6hen name S IsamI then int" %"urt3l2 $alues(IsamuI,2222' 6hen name S ItamI then int" %"urt3l3 $alues(ItamuI,3333' select Q !r"m m%t3l0 6here nameSIramIN 0 r"6 created( S72V select Q !r"m %"urt3l0N NM/ N+ -------------------- ---------- ramu 0000 -- This inserts 0 rec"rd 3ecause the !irst clause a$"id t" check the remaining c"nditi"ns "nce the c"nditi"n is satis!ied( h0 M%,T (SERT 9TH CO()TO(S B&SE)' FRST &() E,SE S72V create ta3le m%t3l0(name $archar2(20',n" num3er(00''N Ta3le created( 47 S72V insert int" m%t3l0 $alues(IramI,000'N 0 r"6 created( S72V insert int" m%t3l0 $alues(IsamI,222'N 0 r"6 created( S72V insert int" m%t3l0 $alues(ItamI,333'N 0 r"6 created( S72V create ta3le %"urt3l0(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l2(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l3(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l:(name $archar2(20',n" num3er(00''N Ta3le created( S72V select Q !r"m m%t3l0N NM/ N+ -------------------- ---------- ram 000 sam 222 tam 333 S72V insert !irst 6hen n"S000 then int" %"urt3l0 $alues(IramuI,0000' 6hen name S I3amI then int" %"urt3l2 $alues(IsamuI,2222' 6hen name S ItamI then int" %"urt3l3 $alues(ItamuI,3333' else int" %"urt3l: $alues(IkamuI,::::' select Q !r"m m%t3l0 6here nameSIramIN 0 r"6 created( S72V select Q !r"m %"urt3l0N NM/ N+ -------------------- ---------- ramu 0000 S72V select Q !r"m %"urt3l2N n" r"6s selected S72V select Q !r"m %"urt3l3N n" r"6s selected S72V select Q !r"m %"urt3l:N n" r"6s selected i0 M%,T (SERT 9TH M%,TB,E T&B,ES S72V create ta3le m%t3l0(name $archar2(20',n" num3er(00''N Ta3le created( 48 S72V insert int" m%t3l0 $alues(IramI,000'N 0 r"6 created( S72V insert int" m%t3l0 $alues(IsamI,222'N 0 r"6 created( S72V insert int" m%t3l0 $alues(ItamI,333'N 0 r"6 created( S72V select Q !r"m m%t3l0N NM/ N+ -------------------- ---------- ram 000 sam 222 tam 333 S72V create ta3le %"urt3l0(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l2(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l3(name $archar2(20',n" num3er(00''N Ta3le created( S72V create ta3le %"urt3l:(name $archar2(20',n" num3er(00''N Ta3le created( S72V insert all int" %"urt3l0 $alues(IramuI,00000' int" %"urt3l2 $alues(IsamuI,22222' int" %"urt3l3 $alues(ItamuI,33333' int" %"urt3l: $alues(IkamuI,:::::' select Q !r"m m%t3l0 6here nameSIramIN : r"6s created( S72V select Q !r"m %"urt3l0N NM/ N+ -------------------- ---------- ramu 00000 S72V select Q !r"m %"urt3l2N NM/ N+ -------------------- ---------- samu 22222 S72V select Q !r"m %"urt3l3N NM/ N+ -------------------- ---------- tamu 33333 S72V select Q !r"m %"urt3l:N NM/ N+ -------------------- ---------- kamu ::::: QQ H"u can use multi ta3les 6ith speci!ied !ields, 6ith duplicate r"6s, 6ith c"nditi"ns, 6ith !irst and else clauses( GROUP BY #sing gr"up 3%, 6e can create gr"ups "! related in!"rmati"n( &"lumns used in select must 3e used 6ith gr"up 3%N "ther6ise it 6as n"t a gr"up 3% e9pressi"n( 49 E1: S72V select Q !r"m empN /M)N+ /NM/ D+1 M,R A-R/DT/ S2 D/)TN+ ------------ --------------- ------------------ ------- ---------------- --------- --------------- <36? SM-TA &2/RK ;000 0<-D/&->0 >000 200 <:?? 22/N S2/SMN ;002 20-G/1->0 3000 300 <;20 =RD S2/SMN ;003 22-G/1->0 ;000 ;00 <:?? RM K#MR SR(S2/SMN ;003 22-DN->< 02000(;;200 <;66 D+N/S MN,/R ;002 02-)R->; <;000 200 <;20 SM K#MR SR(S2/SMN ;003 22-DN-<; 22000 300 6 r"6s selected( S72V select @"3 !r"m /M) gr"up 3% @"3N D+1 -------------------- &2/RK S2/SMN SR(S2/SMN MN,/R S72V select @"3,S#M(S2' !r"m /M) gr"up 3% @"3N D+1 S#M(S2' ----------------- ---------- &2/RK >000 S2/SMN >000 SR(S2/SMN 3:000(;; MN,/R <;000 H&!(6 This 6ill 6"rk as 6here clause 6hich can 3e used "nl% 6ith gr"up 3% 3ecause "! a3sence "! 6here clause in gr"up 3%( S72V select deptn",@"3,sum(sal' T"talPSalar%P+!P/achPDept !r"m emp gr"up 3% deptn",@"3 ha$ing sum(sal' V 3000N D/)TN+ D+1 T+T2PS2RHP+GP/&APD/)T ---------- ---- ---------------- ------------------------- 200 MN,/R <;000 200 SR(S2/SMN 02000(;; 200 &2/RK >000 ;00 S2/SMN ;000 300 SR(S2/SMN 22000 S72V select deptn",@"3,sum(sal' T"talPSalar%P"!P/achPDept !r"m emp gr"up 3% deptn",@"3 ha$ing sum(sal' V 3000 "rder 3% @"3N D/)TN+ D+1 T+T2PS2RHP+GP/&APD/)T 3333333333 33333333333333333 333333333333333333333333 200 &2/RK >000 200 MN,/R <;000 ;00 S2/SMN ;000 200 SR(S2/SMN 02000(;; 300 SR(S2/SMN 22000 %S(6 )E,ETE S72V select Q !r"m /M)N /M)N+ /NM/ D+1 M,R A-R/DT/ S2 D/)TN+ ---------- ---------- ------------------ -------- ---------------- -------- --------------- 0000 RM &2/RK ;000 0<-D/&->: >000 300 50 0002 SM MN,/R ;000 00-DN->0 >;000 300 0003 SM# S2/SMN ;003 0?-G/1->2 >000 302 000: RM# SR(S2/SMN ;002 22-D#N->; :;000 303 S72V D/2/T/ /M) =A/R/ /NM/SISMIN 0 r"6 deleted( S72V select Q !r"m /M)N /M)N+ /NM/ D+1 M,R A-R/DT/ S2 D/)TN+ ----------- ------------ ------------- -------- ------------------ ---------- ----------------- 0000 RM &2/RK ;000 0<-D/&->: >000 300 0003 SM# S2/SMN ;003 0?-G/1->2 >000 302 000: RM# SR(S2/SMN ;002 22-D#N->; :;000 303 S72V D/2/T/ /M) =A/R/ /NM/ 2-K/ IRPPIN 0 r"6 deleted( S72V select Q !r"m /M)N /M)N+ /NM/ D+1 M,R A-R/DT/ S2 D/)TN+ ----------- ----------- -------- ------- ---------------- --------- ------------ 0003 SM# S2/SMN ;003 0?-G/1->2 >000 302 000: RM# SR(S2/SMN ;002 22-D#N->; :;000 303 S72V D/2/T/ GR+M /M) =A/R/ /NM/SISM#IN 0 r"6 deleted( TO )E,ETE &,, RECOR)S S72V D/2/T/ GR+M /M)N 0 r"6 deleted( )E,ETE )%P,C&TE RO9S S72V S/2/&T Q GR+M m%T12N NM/ MRK --------- ---------- RM 000 RM 000 SM 002 SM 002 RM# RM# SM# 003 SM# 003 SM# 003 TM RD ;;; KD 023 02 r"6s selected( S72V delete !r"m m%T12 t0 6here t0(r"6id V (select min(t2(r"6-D' !r"m m%T12 t2 6here t0(name S t2(name and t0(mark S t2(mark'N : r"6s deleted( S72V S/2/&T Q GR+M m%T12N NM/ MRK --------- ---------- RM 000 SM 002 RM# 51 SM# 003 TM RD ;;; KD 023 > r"6s selected( %"in- %P)&TE S72V select Q !r"m /M)N /M)N+ /NM/ D+1 M,R A-R/DT/ S2 D/)TN+ ------------ ------------ ----------- --------- --------------- --------- ------------------ 0000 RM &2/RK ;000 0<-D/&->: >000 300 0002 SM MN,/R ;000 00-DN->0 >;000 300 0003 SM# S2/SMN ;003 0?-G/1->2 >000 302 S72V #)DT/ /M) S/T S2 S ;;;;;,D+1 S ISR(MN,/RI =A/R/ /NM/ 2-K/ IRPPIN 0 r"6 updated( S72V select Q !r"m /M)N /M)N+ /NM/ D+1 M,R A-R/DT/ S2 D/)TN+ ---------- -------------- ------------------ -------- ------------- ------- --------------- 0000 RM SR(MN,/R ;000 0<-D/&->: ;;;;; 300 0002 SM MN,/R ;000 00-DN->0 >;000 300 0003 SM# S2/SMN ;003 0?-G/1->2 >000 302 S72V #)DT/ /M) S/T S2 S ;;;;;,D+1 S ISR(MN,/RIN 3 r"6s updated( S72V select Q !r"m /M)N /M)N+ /NM/ D+1 M,R A-R/DT/ S2 D/)TN+ ---------- ----------- ------------------ ------- --------------- --------- ------------- 0000 RM SR(MN,/R ;000 0<-D/&->: ;;;;; 300 0002 SM SR(MN,/R ;000 00-DN->0 ;;;;; 300 0003 SM# SR(MN,/R ;003 0?-G/1->2 ;;;;; 302 RES%,T: Thus the S72 c"mmands !"r )er!"rming -nserti"n, Deleti"n, M"di!%ing, ltering, #pdating and .ie6ing rec"rds 3ased "n c"nditi"ns has 3een $eri!ied and e9ecuted success!ull%( Creation of !iew"' S.non.m"' Se;#ence' nde1e"' Sa5e 2oint. E1: (o: D= /=.:0 VIEWS FF : FF : FF &M: 52 T" create the $ie6, e9ecute and $eri!% the $ari"us "perati"ns "n $ie6s( OBJECT!E: .ie6s Aelps t" encapsulate c"mple9 8uer% and make it reusa3le( )r"$ides user securit% "n each $ie6 - it depends "n %"ur data p"lic% securit%( #sing $ie6 t" c"n$ert units - i! %"u ha$e a !inancial data in #S currenc%, %"u can create $ie6 t" c"n$ert them int" /ur" !"r $ie6ing in /ur" currenc%( $ie6 is n"thing m"re than a S72 statement that is st"red in the data3ase 6ith an ass"ciated name( $ie6 is actuall% a c"mp"siti"n "! a ta3le in the !"rm "! a prede!ined S72 8uer%( $ie6 can c"ntain all r"6s "! a ta3le "r select r"6s !r"m a ta3le( $ie6 can 3e created !r"m "ne "r man% ta3les 6hich depends "n the 6ritten S72 8uer% t" create a $ie6( .ie6s, 6hich are kind "! $irtual ta3les, all"6 users t" d" the !"ll"6ingB Structure data in a 6a% that users "r classes "! users !ind natural "r intuiti$e( Restrict access t" the data such that a user can see and (s"metimes' m"di!% e9actl% 6hat the% need and n" m"re( &,6ORTHM: ST/) 0B Start the DM1S( ST/) 2B &"nnect t" the e9isting data3ase(D1' ST/) 3B &reate the ta3le 6ith its essential attri3utes( ST/) :B -nsert rec"rd $alues int" the ta3le( ST/) ;B &reate the $ie6 !r"m the a3"$e created ta3le( ST/) 6B Displa% the data presented "n the .-/=( ST/) <B -nsert the rec"rds int" the .-/=, ST/) >B &heck the data3ase "3@ect ta3le and $ie6 the inserted $alues presented ST/) ?B /9ecute di!!erent &"mmands and e9tract in!"rmati"n !r"m the .ie6( ST/) 00B St"p the D1MS( COMM&()S E7EC%TO( CRE&TO( OF T&B,E: Data3ase $ie6s are created using the CRE&TE !E9 statement( .ie6s can 3e created !r"m a single ta3le, multiple ta3les, "r an"ther $ie6( T" create a $ie6, a user must ha$e the appr"priate s%stem pri$ilege acc"rding t" the speci!ic implementati"n( S72V &R/T/ T12/ EMP,OHEE ( 53 /M)2+H//PNM/ .R&AR2(00', /M)2+H//PN+ N#M1/R(>', D/)TPNM/ .R&AR2(00', D/)TPN+ N#M1/R (;', DT/P+GPD+-N DT/ 'N Ta3le created( T&B,E )ESCRPTO(: S72V D/S& EMP,OHEEN NM/ N#22] TH)/ ---------------------------- ------------------------ /M)2+H//PNM/ .R&AR2(00' /M)2+H//PN+ N#M1/R(>' D/)TPNM/ .R&AR2(00' D/)TPN+ N#M1/R(;' DT/P+GPD+-N DT/ CRE&TE !E9 S%(T&7 FOR CRE&TO( OF !E9 CREATE ,OR REPLACE- ,FORCE - VIEW .i$/n!0$ ,(co#u0n1n!0$2 co#u0n1n!0$)- AS Qu$%* ,/it& c&$c3 o4tion-5 CRE&TO( OF !E9 S72V &R/T/ .-/= EMP!E9 S S/2/&T /M)2+H//PNM/, /M)2+H//PN+, D/)TPNM/, D/)TPN+, DT/P+GPD+-N GR+M EMP,OHEEN .ie6 &reated( )ESCRPTO( OF !E9 S72V D/S& /M).-/=N NM/ N#22] TH)/ ---------------------- ---------------------------- /M)2+H//PNM/ .R&AR2(00' /M)2+H//PN+ N#M1/R(>' D/)TPNM/ .R&AR2(00' D/)TPN+ N#M1/R(;' )SP,&H !E9: S72V S/2/&T Q GR+M /M).-/=N /M)2+H//PN /M)2+H//PN+ D/)TPNM/ D/)TPN+ --------------------- ----------------------- ------------------- --------------- R.- 02: /&/ >? .-DH 3:; &S/ 20 RD ?> -T 22 ,-R- 000 &S/ 6< 54 (SERTO( OF !&,%ES (TO !E9 R"6s "! data can 3e inserted int" a $ie6( The same rules that appl% t" the #)DT/ c"mmand als" appl% t" the -NS/RT c"mmand( Aere, 6e can n"t insert r"6s in &#ST+M/RSP.-/= 3ecause 6e ha$e n"t included all the N+T N#22 c"lumns in this $ie6, "ther6ise %"u can insert r"6s in a $ie6 in similar 6a% as %"u insert them in a ta3le( (SERT ST&TEME(T SH(T&7: S72V -NS/RT -NT+ U.-/=PNM/V (&+2#MN NM/0, X' .2#/S(.2#/0,X('N COMM&(): S72V -NS/RT -NT+ /M).-/= .2#/S (ISR-I, 020,I&S/I, 6<,I06-N+.-0?>0I'N 0 R+= &R/T/D( S72V S/2/&T Q GR+M /M).-/=N /M)2+H//PN /M)2+H//PN+ D/)TPNM/ D/)TPN+ --------------------- ----------------------- ------------------- -------------- R.- 02: /&/ >? .-DH 3:; &S/ 20 RD ?> -T 22 ,-R- 000 &S/ 6< SR- 020 &S/ 6< S72V S/2/&T Q GR+M /M)2+H//N /M)2+H//PN /M)2+H//PN+ D/)TPNM/ D/)TPN+ DT/P+GPD -------------------- ----------------------- ------------------- -------------- ----------------- R.- 02: /&/ >? 0;-D#N-0; .-DH 3:; &S/ 20 20-D#N-06 RD ?> -T 22 30-S/)-06 ,-R- 000 &S/ 6< 0:-N+.->0 SR- 020 &S/ 6< 06-N+.->0 )E,ETO( OF !E9: R"6s "! data can 3e deleted !r"m a $ie6( The same rules that appl% t" the #)DT/ and -NS/RT c"mmands appl% t" the D/2/T/ c"mmand( )E,ETE ST&TEME(T SH(T&7: S72V D/2/T/ U.-/=PNM/V=A/R/ U&+2#MN NM/V SM.2#/MN Command: S72V D/2/T/ GR+M /M).-/= =A/R/ /M)2+H//PNM/SISR-IN 0 r"6 deleted( S72V S/2/&T Q GR+M /M).-/=N 55 /M)2+H//PN /M)2+H//PN+ D/)TPNM/ D/)TPN+ --------------------- ----------------------- ------------------ ---------------- R.- 02: /&/ >? .-DH 3:; &S/ 20 RD ?> -T 22 ,-R- 000 &S/ 6< %P)&TE ST&TEME(T: $ie6 can 3e updated under certain c"nditi"nsB The S/2/&T clause ma% n"t c"ntain the ke%6"rd D-ST-N&T( The S/2/&T clause ma% n"t c"ntain summar% !uncti"ns( The S/2/&T clause ma% n"t c"ntain set !uncti"ns( The S/2/&T clause ma% n"t c"ntain set "perat"rs( The S/2/&T clause ma% n"t c"ntain an +RD/R 1H clause( The GR+M clause ma% n"t c"ntain multiple ta3les( The =A/R/ clause ma% n"t c"ntain su38ueries( The 8uer% ma% n"t c"ntain ,R+#) 1H "r A.-N,( &alculated c"lumns ma% n"t 3e updated( ll N+T N#22 c"lumns !r"m the 3ase ta3le must 3e included in the $ie6 in "rder !"r the -NS/RT 8uer% t" !uncti"n( SH(T&7: S72V#)DT/ U.-/=PNM/V S/TU &+2#MN NM/V S U&+2#MN NM/V CU.-/=V =A/R/ U&+2#MN NM/VS.2#/N Command: S72V #)DT/ /M)K.-.-/= S/T /M)2+H//PNM/SIK.-I =A/R/ /M)2+H//PNM/SIR.-IN 0 r"6 updated( S72V S/2/&T Q GR+M /M)K.-.-/=N /M)2+H//PN /M)2+H//PN+ D/)TPNM/ D/)TPN+ --------------------- ----------------------- ------------------- ---------------- K.- 02: /&/ >? .-DH 3:; &S/ 20 RD ?> -T 22 ,-R- 000 &S/ 6< )ROP & !E9: +3$i"usl%, 6here %"u ha$e a $ie6, %"u need a 6a% t" dr"p the $ie6 i! it is n" l"nger needed( SH(T&7: S72V DR+) .-/= U.-/=PNM/V E7&MP,E S72VDR+) .-/= /M).-/=N $ie6 dr"ped CRE&TE & !E9 9TH SE,ECTE) FE,)S: SH(T&7: 56 S72V&R/T/ Y+R R/)2&/Z .-/= U.-/= NM/VS S/2/&T U&+2#MN NM/0VX((GR+M UT12/ NM/VN E7&MP,E3<: S72V &R/T/ +R R/)2&/ .-/= /M)2P.-/=0 S S/2/&T /M)N+, /NM/,S2RH GR+M /M)2N S72V S/2/&T Q GR+M /M)2P.-/=0N E7&MP,E3=: S72V &R/T/ +R R/)2&/ .-/= /M)2P.-/=2 S S/2/&T Q GR+M /M)2 =A/R/ D/)TN+S00N S72V S/2/&T Q GR+M /M)2P.-/=2N (ote: Replace is the ke%3"ard t" a$"id the err"r J"raP00?;Bname is alread% used 3% an e9isting a3@ectK( CH&(6(6 THE CO,%M(/S0 (&ME M THE !E9 )%R(6 &S SE,ECT ST&TEME(T: THPE3:: S+,L &R/T/ +R R/)2&/ .-/= /M)PT+TS2(/-D,NM/,S2' S S/2/&T /M)N+, /NM/,S2RH GR+M /M)2N .ie6 created( /M)N+ /NM/ S 2RH ----------- -------------- ------------ <36? SM-TA 0000 <:?? MRK 00;0 <;6; =-22 0;00 <6<> D+AN 0>00 <;<> T+M 0;00 <;:> T#RN/R 0;00 6 r"6s selected( .ie6 created( S72V S/2/&T Q GR+M /M)PT+TS2N /M)N+ /NM/ S2RH M,RN+ D/)TN+ ------------ ------------ ------------- ------------- ------------- <;<> T+M 0;00 <2?> 00 <;:> T#RN/R 0;00 <2?> 00 .ie6 created( THPE3<: S72V &R/T/ +R R/)2&/ .-/= /M)PT+TS2 S S/2/&T /M)N+ R/-DR, /NM/ RNM/R, S2RH RS2R GR+M /M)2N S72V S/2/&T Q GR+M /M)PT+TS2N E7&MP,E FOR JO( !E9: 57 THPE3=: S72V &R/T/ +R R/)2&/ .-/= D/)TP/M) S S/2/&T (/M)N+ R/-DR, (/NM/ R/M)NM/R, (D/)TN+ RDN+R, 1(DNM/ RDPNM/R, 1(2+& RDP2+&R GR+M /M)2 ,D/)MT 1 =A/R/ (D/)TN+S1(D/)TN+N S72V S/2/&T Q GR+M D/)TP/M)N /-D NM/ S2 -------- ---------- ---------- ---------- <36? SM-TA 0000 <:?? MRK 00;0 <;6; =-22 0;00 <6<> D+AN 0>00 <;<> T+M 0;00 <;:> T#RN/R 0;00 6 r"6s selected( .ie6 created( /-D NM/ S2 --------- ----------- ---------- <36? SM-TA 0000 <:?? MRK 00;0 <;6; =-22 0;00 <6<> D+AN 0>00 <;<> T+M 0;00 <;:> T#RN/R 0;00 6 r"6s selected( .ie6 created( /-D /M)NM/ DN+ DPNM/ DP2+& ---------- ---------------- ---------- ----------------- ---------------------- <;<> T+M 00 &&+#NT N/= H+RK <;:> T#RN/R 00 &&+#NT N/= H+RK <36? SM-TA 20 S2/S &A-&,+ <6<> D+AN 20 S2/S &A-&,+ <:?? MRK 30 R/S/R&A O#R-&A <;6; =-22 30 R/S/R&A O#R-&A !E9 RE&) O(,H &() CHEC8 OPTO(: RE&) O(,H C,&%SE: H"u can create a $ie6 6ith read "nl% "pti"n 6hich ena3le "ther t" "nl% 8uer% (n" DM2 "perati"n can 3e per!"rmed t" this t%pe "! a $ie6( E7&MP,E3>: 58 S72V&R/T/ +R R/)2&/ .-/= /M)PN+PDM2 S S/2/&T Q GR+M /M)2 =-TA R/D +N2HN 9TH CHEC8 OPTO( C,&%SE: E7&MP,E3>: S72V &R/T/ +R R/)2&/ .-/= /M)P&KP+)T-+N S S/2/&T /M)N+, /NM/, S2RH, D/)TN+ GR+M /M)2 =A/R/ D/)TN+S00 =-TA &A/&K +)T-+NN S72V S/2/&T Q GR+M /M)P&KP+)T-+NN JO( !E9: E7&MP,E3?: S72V &R/T/ +R R/)2&/ .-/= D/)TP/M)P.-/= S S/2/&T (/M)N+, (/NM/, (D/)TN+, 1(DNM/, 1(2+& GR+M /M)2 , D/)MT 1 =A/R/ (D/)TN+S1(D/)TN+N S72V S/2/&T Q GR+M D/)TP/M)P.-/=N .ie6 created( /M)N+ /NM/ S2RH D/)TN+ ----------- ------------- --------------- -------------- <;<> T+M 0;00 00 <;:> T#RN/R 0;00 00 .ie6 created( /M)N+/NM/D/)TN+ DNM/ 2+& ----------- ------------ ------------- ------------- ------- <;<> T+M 00 &&+#NT N/= H+RK <;:> T#RN/R 00 &&+#NT N/= H+RK <36? SM-TA 20 S2/S &A-&,+ <6<> D+AN 20 S2/S &A-&,+ <:?? MRK 30 R/S/R&A O#R-&A <;6; =-22 30 R/S/R&A O#R-&A 6 r"6s selected( FORCE !E9: E7&MP,E3@: S72V &R/T/ +R R/)2&/ G+R&/ .-/= MH.-/= S S/2/&T Q GR+M EHON S72V S/2/&T Q GR+M MH.-/=N S72V &R/T/ T12/ EHO S S/2/&T /M)N+,/NM/,S2RH,D/)TN+ GR+M /M)2N 59 S72V S/2/&T Q GR+M EHON S72V &R/T/ +R R/)2&/ G+R&/ .-/= MH.-/= S S/2/&T Q GR+M EHON S72V S/2/&T Q GR+M MH.-/=N =arningB .ie6 created 6ith c"mpilati"n err"rs( S/2/&T Q GR+M MH.-/= Q /RR+R at line 0B +R-0:063B $ie6 R:03?(MH.-/=R has err"rs Ta3le created( /M)N+ /NM/ S2RH D/)TN+ ---------- -------------------- ---------- ---------- ----------------- <36? SM-TA 0000 20 <:?? MRK 00;0 30 <;6; =-22 0;00 30 <6<> D+AN 0>00 20 <;<> T+M 0;00 00 <;:> T#RN/R 0;00 00 6 r"6s selected( .ie6 created( /M)N+ /NM/ S2RH D/)TN+ ----------- ------------- ------------- --------------- <36? SM-TA 0000 20 <:?? MRK 00;0 30 <;6; =-22 0;00 30 <6<> D+AN 0>00 20 <;<> T+M 0;00 00 <;:> T#RN/R 0;00 00 6 r"6s selected COMP,(6 & !E9: SH(T&7: 2T/R .-/= U.-/=PNM/V &+M)-2/N E7&MP,E: S72V 2T/R .-/= MH.-/= &+M)-2/N 60 RES%,TB Thus the S72 c"mmands !"r .ie6 has 3een $eri!ied and e9ecuted success!ull%( S.non.m" E1: (o: D= /=.<0 FF : FF : FF &M: T" create the S%n"n%ms and $eri!% the $ari"us "perati"ns "n S%n"n%ms OBJECT!E: ".non.m is an alias !"r an% ta3le, $ie6, materialiFed $ie6, se8uence, pr"cedure, !uncti"n, package, t%pe, Da$a class schema "3@ect, user-de!ined "3@ect t%pe, "r an"ther s%n"n%m( 1ecause a s%n"n%m is simpl% an alias, it re8uires n" st"rage "ther than its de!initi"n in the data dicti"nar%( 61 S%n"n%ms are "!ten used !"r securit% and c"n$enience( G"r e9ample, the% can d" the !"ll"6ingB Mask the name and "6ner "! an "3@ect )r"$ide l"cati"n transparenc% !"r rem"te "3@ects "! a distri3uted data3ase Simpli!% S72 statements !"r data3ase users /na3le restricted access similar t" specialiFed $ie6s 6hen e9ercising !ine-grained access c"ntr"l H"u can create 3"th pu3lic and pri$ate s%n"n%ms( 2#$lic s%n"n%m is "6ned 3% the special user gr"up named )#12-& and e$er% user in a data3ase can access it( 2ri5ate s%n"n%m is in the schema "! a speci!ic user 6h" has c"ntr"l "$er its a$aila3ilit% t" "thers( &,6ORTHM: ST/) 0B Start the DM1S( ST/) 2B &"nnect t" the e9isting data3ase(D1' ST/) 3B &reate the ta3le 6ith its essential attri3utes( ST/) :B -nsert rec"rd $alues int" the ta3le( ST/) ;B &reate the s%n"n%ms !r"m the a3"$e created ta3le "r an% data "3@ect( ST/) 6B Displa% the data presented "n the s%n"n%ms( ST/) <B -nsert the rec"rds int" the s%n"n%ms, ST/) >B &heck the data3ase "3@ect ta3le and $ie6 the inserted $alues presented ST/) ?B St"p the D1MS( E1am2le: S.nta1: S+,LCRE&TE SH(O(HM s%n"n%mName FOR "3@ectN +R S+,L&R/T/ SHN+NHM tt !"r te"t:I Dependent +@ect - tt (SHN+NHM NM/ ' Re!erenced +3@ect - te"t: (T12/ NM/' %S&6E: #sing emp %"u can per!"rm DM2 "perati"n as %"u ha$e create s%sn"nm !"r ta3le "3@ect -! empl"%ees ta3le is dr"pped then status "! emp 6ill 3e in$alid( 2"cal Dependencies are aut"maticall% managed 3% "racle ser$er( 62 COMM&()S: CRE&TE THE T&B,E S72V &R/T/ T12/ studentPta3le(RegPN" num3er(;',NM/ $archar2(;',MRK num3er(3''N Ta3le created( (SERT THE !&,%ES (TO THE T&B,E S72V insert int" studentPta3le $alues(00000,IramI,>;'N 0 r"6 created( S72V insert int" studentPta3le $alues(00002,IsamI,<;'N 0 r"6 created( S72V insert int" studentPta3le $alues(00003,IsamuI,?;'N 0 r"6 created( S72V select Q !r"m ST#D/NTPT12/N R/,PN+ NM/ MRK ------------ --------- ---------- 00000 ram >; 00002 sam <; 00003 samu ?; CRE&TE THE SH(O(HM FROM T&B,E S72V &R/T/ SHN+NHM ST#D/NTPSHN+NHM G+R ST#D/NTPT12/N S%n"n%m created( )SP,&H THE !&,%ES OF T&B,E BH %S(6 THE SHS(O(HM S72V select Q !r"m ST#D/NTPSHN+NHMN R/,PN+ NM/ MRK ------------ ------------- ---------- 00000 ram >; 00002 sam <; 00003 samu ?; (SERT THE !&,%ES TO THE SH(O(HM 63 S72V insert int" studentPSHN+NHM $alues(00006,IRDI,>0'N 0 r"6 created( )SP,&H THE !&,%ES ( BOTH T&B,E &() SH(O(HM S72V select Q !r"m ST#D/NTPT12/N R/,PN+ NM/ MRK ------------ ----------- ---------- 00000 ram >; 00002 sam <; 00003 samu ?; 00006 RD >0 S72V select Q !r"m ST#D/NTPSHN+NHMN R/,PN+ NM/ MRK ----------- --------- --------- 00000 ram >; 00002 sam <; 00003 samu ?; 00006 RD >0 HO% C&( %P)&TE THE T&B,E BH %S(6 SH(O(HM S72V #)DT/ ST#D/NTPSHN+NHM S/T MRKS000 =A/R/ R/,PN+S00006N 0 r"6 updated( S72V select Q !r"m ST#D/NTPSHN+NHMN R/,PN+ NM/ MRK ------------ ----------- ---------------- 00000 ram >; 00002 sam <; 00003 samu ?; 00006 RD 000 S72V select Q !r"m ST#D/NTPT12/N R/,PN+ NM/ MRK ------------ ------------- --------- 00000 ram >; 00002 sam <; 00003 samu ?; 64 00006 RD 000 TO )ROP SHS(O(HM S72V DR+) SHN+NHM ST#D/NTPSHN+NHMN S%n"n%m dr"pped( B%T 9E C&( %SE THE T&B,E S72V select Q !r"m ST#D/NTPT12/N R/,PN+ NM/ MRK ------------ ------------ ------------ 00000 ram >; 00002 sam <; 00003 samu ?; 00006 RD 000 RES%,T: Thus the S72 c"mmands !"r creati"n and $ari"us "perati"n "n S%n"n%ms has 3een $eri!ied and e9ecuted success!ull%( Se;#ence E1: (o: D= /=.=0 FF : FF : FF &M: T" create the Se8uence and $eri!% the $ari"us "perati"ns "n Se8uence t" get the incremented num3er( OBJECT!E: The se8uence generat"r pr"$ides a se8uential series "! num3ers( The se8uence generat"r is especiall% use!ul in multiuser en$ir"nments !"r generating uni8ue se8uential num3ers 6ith"ut the "$erhead "! disk -4+ "r transacti"n l"cking Se8uence num3ers are integers "! up t" 3> digits de!ined in the data3ase( se8uence de!initi"n indicates general in!"rmati"n, such as the !"ll"6ingB The name "! the se8uence 65 =hether the se8uence ascends "r descends The inter$al 3et6een num3ers =hether +racle Data3ase sh"uld cache sets "! generated se8uence num3ers in mem"r% &,6ORTHM: Step 0B Start the DM1S( Step 2B &"nnect t" the e9isting data3ase (D1' Step 3B &reate the se8uence 6ith its essential "pti"nal parameter( Step :B Displa% the data presented "n the se8uence 3% using pseud" c"lumn( Step ;B lter the se8uence 6ith di!!erent "pti"nal parameter( Step 6B Dr"p the se8uence Step <B St"p the D1MS( Creatin- a Se;#ence H"u create a se8uence using the &R/T/ S/7#/N&/ statement, 6hich has the !"ll"6ing( SH(T&7: S+,LCRE&TE SE+%E(CE se8uencePname YST&RT 9TH startPnumZ Y(CREME(T BH incrementPnumZ Y [ M&7!&,%E ma9imumPnum ^ (OM&7!&,%E \ Z Y [ M(!&,%E minimumPnum ^ (OM(!&,%E \ Z Y [ CHC,E ^ (OCHC,E \ Z Y [ C&CHE cachePnum ^ (OC&CHE \ Z Y [ OR)ER ^ (OOR)ER \ ZN =here sequence_name is the name "! the se8uence( start_num is the integer t" start the se8uence( The de!ault start num3er is 0( 66 increment_num is the integer t" increment the se8uence 3%( The de!ault increment num3er is 0( The a3s"lute $alue "! increment_num must 3e less than the di!!erence 3et6een maximum_num and minimum_num( maximum_num is the ma9imum integer "! the se8uenceN maximum_num must 3e greater than "r e8ual t" start_num, and maximum_num must 3e greater than minimum_num( (OM&7!&,%E speci!ies the ma9imum is 002< !"r an ascending se8uence "r *0 !"r a descending se8uence( N+ME.2#/ is the de!ault( minimum_num is the minimum integer "! the se8uenceN minimum_num must 3e less than "r e8ual t" start_num, and minimum_num must 3e less than maximum_num( (OM(!&,%E speci!ies the minimum is 0 !"r an ascending se8uence "r *0026 !"r a descending se8uence( N+M-N.2#/ is the de!ault( CHC,E means the se8uence generates integers e$en a!ter reaching its ma9imum "r minimum $alue( =hen an ascending se8uence reaches its ma9imum $alue, the ne9t $alue generated is the minimum( =hen a descending se8uence reaches its minimum $alue, the ne9t $alue generated is the ma9imum( (OCHC,E means the se8uence cann"t generate an% m"re integers a!ter reaching its ma9imum "r minimum $alue( N+&H&2/ is the de!ault( cache_num is the num3er "! integers t" keep in mem"r%( The de!ault num3er "! integers t" cache is 20( The minimum num3er "! integers that ma% 3e cached is 2( The ma9imum integers that ma% 3e cached is determined 3% the !"rmula &/-2(maximum_num - minimum_num'41S(increment_num'( (OC&CHE means n" caching( This st"ps the data3ase !r"m pre-all"cating $alues !"r the se8uence, 6hich pre$ents numeric gaps in the se8uence 3ut reduces per!"rmance( ,aps "ccur 3ecause cached $alues are l"st 6hen the data3ase is shut d"6n( -! %"u "mit &&A/ and N+&&A/, the data3ase caches 20 se8uence num3ers 3% de!ault( OR)ER guarantees the integers are generated in the "rder "! the re8uest( H"u t%picall% use +RD/R 6hen using Real pplicati"n &lusters, 6hich are set up and managed 3% data3ase administrat"rs( (OOR)ER d"esnMt guarantee the integers are generated in the "rder "! the re8uest( N++RD/R is the de!ault( E1am2le: : Command: S72V &R/T/ S/7#/N&/ se80 -N&R/M/NT 1H 0 STRT 6ith 0 ME.2#/ ; M-N.2#/ 0N Se;#ence created. 67 TO )SP,&H THE !&,%ES OF SE+%E(CES !ter creating se8uence use ne9t$al as ne9t$al is used t" generate se8uence $alues S72V select se80(ne9t$al !r"m dualN N/ET.2 ---------- 0 S72V select se80(ne9t$al !r"m dualN N/ET.2 ---------- 2 S72V select se80(ne9t$al !r"m dualN N/ET.2 ---------- 3 S72V select se80(curr$al !r"m dualN &#RR.2 ---------- 3 The !"ll"6ing is the list "! a$aila3le pseud" c"lumns in +racle( P"e#do Col#mn Meanin- &#RR.2 - Returns the current $alue "! a se8uence( N/ET.2 - Returns the ne9t $alue "! a se8uence( N#22 - Return a null $alue( R+=-D - Returns the R+=-D "! a r"6( See R+=-D secti"n 3el"6( R+=N#M - Returns the num3er indicating in 6hich "rder +racle selects r"6s( Girst r"6 selected 6ill 3e R+=N#M "! 0 and sec"nd r"6 R+=N#M "! 2 and s" "n( SHSDT/ - Returns current date and time( #S/R - Returns the name "! the current user( #-D - Returns the uni8ue num3er assigned t" the current user( TO &,TER THE SE+%E(CES 68 alter S/7#/N&/ se80 ma9$alue 2; -N&R/M/NT 1H 2 c%cle cache 2 dr"p S/7#/N&/ se80N E7&MP,E: < &R/T/ S/7#/N&/ se82 -N&R/M/NT 1H 0 start 6ith 0 ma9$alue ; min$alue 0 c%cle &&A/ :N E7&MP,E: = &R/T/ S/7#/N&/ se83 -N&R/M/NT 1H -0 start 6ith 2 ma9$alue ; min$alue 0N E7&MP,E: > &R/T/ S/7#/N&/ se83 -N&R/M/NT 1H -0 start 6ith 2 ma9$alue ; min$alue 0 c%cle cache :N E7&MP,E: ? &R/T/ S/7#/N&/ se80 -N&R/M/NT 1H 0 start 6ith 0 ma9$alue 00 min$alue 0N 69 E7&MP,E: @ create ta3le test0(a num3er primar% ke%'N TO (SERT THE !&,%ES FROM SE+%E(CES TO T&B,E: insert int" test0 $alues(se80(ne9t$al' TO )ROP SE+%E(CES dr"p se8uence se8uenceNme RES%,T: Thus the S72 c"mmands !"r creati"n and $ari"us "perati"ns "n Se8uence has 3een $eri!ied and e9ecuted success!ull%( nde1e" E1: (o: D= /=.>0 FF : FF : FF &M: T" create the Index for the tabe data and $eri!% the $ari"us "perati"ns "n Index( &,6ORTHM: ST/) 0B Start the DM1S( ST/) 2B &"nnect t" the e9isting data3ase (D1' ST/) 3B &reate the ta3le 6ith its essential attri3utes( ST/) :B -nsert rec"rd $alues int" the ta3le( ST/) ;B &reate the -nde9 !r"m the a3"$e created ta3le "r an% data "3@ect( ST/) 6B Displa% the data presented "n the -nde9( ST/) <B St"p the D1MS( 70 nde1 The inde9es are special "3@ects 6hich 3uilt "n t"p "! ta3les( The inde9es can d" "perati"n like S/2/&T , D/2/T/ and #)DT/ statement !aster t" manipulate a large am"unt "! data( n -ND/E can als" 3e called a ta3le and it has a data structure( n -ND/E is created "n c"lumns "! a ta3le( +ne ta3le ma% c"ntain "ne "r m"re -ND/E ta3les The S+, ()E7 doe" the followin-: -ND/E/S can l"cate in!"rmati"n 6ithin a data3ase $er% !ast( n -ND/E makes a catal"g "! r"6s "! a data3ase ta3le as r"6 can 3e p"inted 6ithin a !racti"n "! time 6ith a minimum e!!"rt( ta3le -ND/E is a data3ase structure 6hich arranges the $alues "! "ne "r m"re c"lumns in a speci!ic "rder( The per!"rmance "! an -ND/E can n"t 3e rec"gniFed much 6hen dealing 6ith relati$el% small ta3les( -ND/E can 6"rk pr"perl% and 8uickl% !"r the c"lumns that ha$e man% di!!erent $alues( -t takes a l"ng time t" !ind an in!"rmati"n !"r "ne "r c"m3inati"n "! c"lumns !r"m a ta3le 6hen there are th"usands "! rec"rds in the ta3le( -n that case i! inde9es are created "n that c"lumns, 6hich are accessed !re8uentl%, the in!"rmati"n can 3e retrie$ed 8uickl%( The -ND/E !irst s"rts the data and then it assigns an identi!icati"n !"r each r"6( The -ND/E ta3le ha$ing "nl% t6" c"lumns, "ne is a r"6id and an"ther is inde9ed-c"lumn ("rdered'( =hen data is retrie$ed !r"m a data3ase ta3le 3ased "n the inde9ed-c"lumn, the inde9 p"inter searches the r"6id and 8uickl% l"cates that p"siti"n(in the actual ta3le and displa% the r"6s s"ught !"r( 71 How it differ from 5iew n -ND/E is als" a ta3le( S" it has a data structure( -ND/E/S are p"inters that represents the ph%sical address "! a data( n -ND/E is created "n c"lumns "! a ta3le( n -ND/E makes a catal"g 3ased "n "ne "r m"re c"lumns "! a ta3le( +ne ta3le ma% c"ntain "ne "r m"re -ND/E ta3les( n -ND/E can 3e created "n a single c"lumn "r c"m3inati"n "! c"lumns "! a data3ase ta3le( T.2e" of nde1e": 0( Simple -nde9 2( &"mp"site -nde9 Command S&MP,E T&B,E: S72V S/2/&T Q GR+M ST#D/NTPT12N S2PN+R/,PN+ NM/ S/E D+1 T+T2P)/R&/NT,/ M+1-2/PN+ DDR/SS 12++D --------- ------------ -------------------- ------ ----------- ------------------------------- ----------------- ------------- --------- 0 00000 RM M 00-D/&->; <; ?<;6:3;<>? )2+T(N"B3046 1& 1C 2 00002 RD M 06-DN-<: ><(; ?:;6:3;:;> 1& Nager +C 3 00003 N-RM2 G 22-G/1->< ?;(; ?:6003;:00 SKTA- Nager C : 0000: nitha G 0;-MR->< 6:(3 ?:6003;;;; NN Nager 1C Sim2le nde1: =hen inde9 is created "n "ne c"lumn it is called as simple inde9( S.nta1: &R/T/ -ND/E U-ND/EPNM/V +N UT12/PNM/V (&+2PNM/'N E1: S72V create inde9 m%-nde9 "n studentPt3l(name'N -nde9 created( Pnote" -nde9 sh"uld 3e created "n c"lumns 6hich 6e regularl% use in the 6here clause( =hen a inde9 is created a separate structure is created 6ith !irst c"lumn is R+=-D and sec"nd c"lumn as inde9ed c"lumn( The R"6s in the inde9 6ill 3e arranged in the ascending "rder "! inde9ed c"lumn( Com2o"ite nde1: 6hen -nde9 is created multiple c"lumns it is called c"mp"site inde9( E1: 72 S72V create inde9 m%&"mp-nde9 "n studentPt3l(D+1,DDR/SS'N -nde9 created( The a3"$e inde9 m.Com2nde1 is used "nl% 6hen 3"th the c"lumns are used in the 6here clause( )i"ad5anta-e" of inde1: -nde9 6ill c"nsume mem"r%( The per!"rmance "! DM2 c"mmand 6ill 3e decreased( -nde9 can als" 3e categ"riFed t6" t%pesB 0( #ni8ue inde9 2( N"n-uni8ue inde9 %ni;#e nde1: -! the inde9ed c"lumn c"ntains uni8ue $alue it is called uni8ue inde9( uni8ue inde9 is aut"maticall% created( =hen 6e create a ta3le 6ith primar% ke% c"nstraint "r uni8ue c"nstraint( Cmd S72V create uni8ue inde9 m%-nde9 "n studentPt3l(name'N (on3#ni;#e inde1: -! an inde9 c"lumn c"ntains duplicated $alues the% are called as n"n-uni8ue inde9( See to inde1 ta$le": S72V Select inde9Pname !r"m userPinde9esN -ND/EPNM/ ----------------------- MH&+M)-ND/E MH-ND/E SHSP&000006: 73 7uer% t" see list "! all the inde9es( S72V Select -ND/EPNM/,T12/PNM/ !r"m userPinde9esN -ND/EPNM/ T12/PNM/ ------------------------------ ------------------------------ SHSP&000006: T12P)K/H MH&+M)-ND/E ST#D/NTPT12 MH-ND/E ST#D/NTPT12 7uer% t" see list "! all the inde9es al"ng 6ith c"lumn name( S72V Select inde9Pname, ta3lePname, c"lumnPname !r"m userPindPc"lumnsN -ND/EPNM/ T12/PNM/ &+2#MNPNM/ -------------------- ------------------- ------------------------ MH&+M)-ND/E ST#D/NTPT12 DDR/SS MH&+M)-ND/E ST#D/NTPT12 D+1 MH-ND/E ST#D/NTPT12 NM/ . S72V Desc userPinde9esN S72V Desc userPindPc"lumnsN F#nction $a"ed inde1: =hen inde9 is created 3% using !uncti"ns it is called as !uncti"n 3ased inde9( E1: S72V &R/T/ -ND/E m%Gunc-nde9 +N ST#D/NTPT12(l"6er(name''N -nde9 created( To dro2 on inde1: E1: S72V dr"p inde9 inde9P"!PstudentPt3lN 74 RES%,T: Thus the S72 c"mmands !"r creati"n and $ari"us "perati"ns "n -nde9es has 3een $eri!ied and e9ecuted success!ull%( S&!E PO(T E1: (o: D= /=.?0 FF : FF : FF &M: T" create the S./ )+-NT !"r the transacti"n and $eri!% the $ari"us "perati"ns "! T&2 c"mmands( OBJECT!E: The S&!EPO(T statement names and marks the current p"int in the pr"cessing "! a transacti"n( =ith the RO,,B&C8 TO statement, sa$ep"ints und" parts "! a transacti"n instead "! the 6h"le transacti"n( n implicit sa$ep"int is marked 3e!"re e9ecuting an (SERT' %P)&TE' or )E,ETE statement( -! the statement !ails, a r"ll3ack t" the implicit sa$ep"int is d"ne( N"rmall%, @ust the !ailed S72 statement is r"lled 3ack, n"t the 6h"le transacti"nN i! the statement raises an unhandled e9cepti"n, the h"st en$ir"nment &,6ORTHM: ST/) 0B Start the DM1S( ST/) 2B &"nnect t" the e9isting data3ase (D1' ST/) 3B &reate the ta3le 6ith its essential attri3utes( 75 ST/) :B -nsert rec"rd $alues int" the ta3le "r per!"rm an% kind "! DM2 "perati"n( ST/) ;B &reate the S&!E PO(Ts !"r s"me set "! statement "n the transacti"n "! data3ase "3@ect( ST/) 6B #se the COMMT c"mmand t" sa$e the e!!ect "! the pre$i"us c"mmand "perati"n e9cept DD2 c"mmand ST/) <B #se the RO,,B&C8 TO SPF,&B,E 4 RO,,B&C8 c"mmand !"r rest"re the data3ase status up t" the sa$e p"int ST/) >B &heck the status "! the data3ase( ST/) ?B St"p the D1MS( S.nta1B S./)+-NTUS./)+-NTPNM/VN E1B S72V create ta3le +RD/RP)R+&/SS-N,( +rderP-D num3er(3', )r"ductP-D $archar2(00', 7uantit% num3er(3,2', )rice num3er(:,2' 'N Ta$le created. S72V insert int" +RD/RP)R+&/SS-N, $alues(000,IR-&/-22I,I6(;I,I30(;0I'N : row created. S72V insert int" +RD/RP)R+&/SS-N, $alues(002,I+-2I,I2(0I,I?0(;0I'N : row created. S72V S/2/&T Q GR+M +RD/RP)R+&/SS-N,N +RD/RP-D )R+D#&TP-D 7#NT-TH )R-&/ -------------- ---------------- -------------- ---------- 000 R-&/-22 6(; 30(; 002 +-2 2 ?0(; S72V COMMTI Commit com2lete( 76 S72V insert int" +RD/RP)R+&/SS-N, $alues(003,I1,SI,I2I,I?;I'N : row created. S72V insert int" +RD/RP)R+&/SS-N, $alues(00:,I=T/R 1+TSI,I2I,I20I'N : row created. S72V S&!EPO(T &I Sa5e2oint created. S72V insert int" +RD/RP)R+&/SS-N, $alues(00;,I/,,I,I>I,I:0(;0I'N : row created. S72V insert int" +RD/RP)R+&/SS-N, $alues(006,ISAM)++I,I0I,I<;(;0I'N : row created. S72V S&!EPO(T BI Sa5e2oint created. S72V insert int" +RD/RP)R+&/SS-N, $alues(00<,I1R S+)I,I0I,I:;(;0I'N : row created. S72V insert int" +RD/RP)R+&/SS-N, $alues(00>,IT+N/RI,I0I,I<;(;0I'N : row created. S72V S&!EPO(T CI Sa5e2oint created. S72V insert int" +RD/RP)R+&/SS-N, $alues(00?,IS#,RI,I2(0I,I60(;0I'N : row created. S72V S/2/&T Q GR+M +RD/RP)R+&/SS-N,N +RD/RP-D )R+D#&TP-D 7#NT-TH )R-&/ -------------- ---------------- --------------- ---------- 000 R-&/-22 6(; 30(; 002 +-2 2 ?0(; 003 1,S 2 ?; 77 00: =T/R 1+TS 2 20 00; /,, > :0(; 006 SAM)++ 0 <;(; 00< 1R S+) 0 :;(; 00> T+N/R 0 <;(; 00? S#,R 2 60(; ? r"6s selected( S72V R+221&K T+ 1N Roll$ack com2lete. S72V S/2/&T Q GR+M +RD/RP)R+&/SS-N,N +RD/RP-D )R+D#&TP-D 7#NT-TH )R-&/ ---------------- ------------------- -------------- ------------- 000 R-&/-22 6(; 30(; 002 +-2 2 ?0(; 003 1,S 2 ?; 00: =T/R 1+TS 2 20 00; /,, > :0(; 006 SAM)++ 0 <;(; 6 r"6s selected( S72V R+221&K T+ N Roll$ack com2lete. S72V S/2/&T Q GR+M +RD/RP)R+&/SS-N,N +RD/RP-D )R+D#&TP-D 7#NT-TH )R-&/ ---------------- -------------------- ---------------- ------------ 000 R-&/-22 6(; 30(; 002 +-2 2 ?0(; 003 1,S 2 ?; 00: =T/R 1+TS 2 20 S72V R+221&KN Roll$ack com2lete. 78 S72V S/2/&T Q GR+M +RD/RP)R+&/SS-N,N +RD/RP-D )R+D#&TP-D 7#NT-TH )R-&/ --------------- -------------------- ---------------- ------------- 000 R-&/-22 6(; 30(; 002 +-2 2 ?0(; S72V R+221&KN Roll$ack com2lete. S72V S/2/&T Q GR+M +RD/RP)R+&/SS-N,N +RD/RP-D )R+D#&TP-D 7#NT-TH )R-&/ ---------------- ------------------- ---------------- ----------- 000 R-&/-22 6(; 30(; 002 +-2 2 ?0(; 79 RES%,T: Thus the S72 c"mmands !"r creati"n and $ari"us "perati"ns "n transacti"n (T&2 &+MMND' sa$e p"int has 3een $eri!ied and e9ecuted success!ull% Creatin- an Em2lo.ee data$a"e to "et 5ario#" con"traint" in R)BMS E1: (o: D> FF : FF : FF &M: t the end "! this e9ercise students are a3le T" di!!erentiate 3et6een sel! re!erential c"nstraints and !"reign ke% c"nstraint( T" re!er a !ield "! a gi$en ta3le "r an"ther ta3le 3% using !"reign ke%( T" appl% check c"nstraint 5 de!ault c"nstraint in an e!!ecti$e manner( &,6ORTHM: ST/) 0B Start the DM1S( ST/) 2B &"nnect t" the e9isting data3ase (D1' ST/) 3B &reate the ta3le 6ith its essential c"nstraint( ST/) :B -nsert rec"rd $alues int" the ta3le and then check the c"nstraint( ST/) ;B disa3le the c"nstraints and insert the $alues int" the ta3le( ST/) 6B i! %"u 6ant t" re-ena3le the c"nstraint then ena3le %"u can d"( ST/) <B St"p the D1MS( 80 CO(STR&(TS &"nstraints are part "! the ta3le de!initi"n that limits and restricti"n "n the $alue entered int" its c"lumns( (TE6RTH CO(STR&(T n integrit% c"nstraint is a mechanism used 3% "racle t" pre$ent in$alid data entr% int" the ta3le( -t has en!"rcing the rules !"r the c"lumns in a ta3le( The t%pes "! the integrit% c"nstraints areB a' D"main -ntegrit% 3' /ntit% -ntegrit% c' Re!erential -ntegrit% THPES OF CO(STR&(TS: 0' )rimar% ke% 2' G"reign ke%4re!erences 3' &heck :' #ni8ue ;' N"t null 6' Null <' De!ault CO(STR&(TS C&( BE CRE&TE) ( THREE 9&HS: 81 0' &"lumn le$el c"nstraints 2' Ta3le le$el c"nstraints 3' #sing DD2 statements-alter ta3le c"mmand OPER&TO( O( CO(STR&(TB i' /N12/ ii' D-S12/ iii' DR+) PRM&RH 8EH CO(STR&(TS primar% ke% a$"ids duplicati"n "! r"6s and d"es n"t all"6 null $alues( -t can 3e de!ined "n "ne "r m"re c"lumns in a ta3le and is used t" uni8uel% identi!% each r"6 in a ta3le( These $alues sh"uld ne$er 3e changed and sh"uld ne$er 3e null( ta3le sh"uld ha$e "nl% "ne primar% ke%( -! a primar% ke% c"nstraint is assigned t" m"re than "ne c"lumn "r c"m3inati"n "! c"lumn is said t" 3e c"mp"site primar% ke%, 6hich can c"ntain 06 c"lumns( Col#mn le5el con"traint" #"in- 2rimar. ke.: +%ERH: := 703( =rite a 8uer% t" create primar% c"nstraints 6ith c"lumn le$el S.nta1: &"lumn le$el c"nstraints using primar% ke%( S72V &R/T/U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V (S-O/'UTH)/ +G &+NSTR-NTSV, &+2#MN NM/(0 UDTTH)/V (S-O/' XXXXXXXXXXX'N Command: S72V &R/T/ T12/ T12P)K/H( RegN" N#M1/R(;' PRM&RH 8EH, Name .R&AR2(20', NHPS#1PMRK N#M1/R(3' 'N Ta$le created. S72V insert int" T12P)K/H $alues(00000,Ira@uI,<;'N : row created. S72V insert int" T12P)K/H $alues(00002,Ira@I,>;'N : row created. S72V insert int" T12P)K/H $alues(0,IKa@I,22'N : row created. S72V insert int" T12P)K/H $alues(N#22,IKa@I,22'N insert int" T12P)K/H $alues(N#22,IKa@I,22' Q /RR+R at line 0B OR&3D:>DD: cannot in"ert (%,, into /SSE(TH,S.STB,FP8EHS.SRE6(OS0 S72V insert int" T12P)K/H $alues(00002,IRDNI,?;'N insert int" T12P)K/H $alues(00002,IRDNI,?;' Q /RR+R at line 0B 82 OR&3DDDD:: #ni;#e con"traint /SE(TH,.SHSFCDD::@?D0 5iolated S72V insert int" T12P)K/H $alues(00003,IRDI,>;'N : row created. S72V select Q GR+M T12P)K/HN R/,N+ NM/ NHPS#1PMRK ----------- ------------- ----------------------------- 00000 ra@u <; 00002 ra@ >; 0 Ka@ 22 00003 RD >; Col#mn le5el con"traint" #"in- 2rimar. ke. with namin- con5ention: +%ERH: :> 70:( =rite a 8uer% t" create primar% c"nstraints 6ith c"lumn le$el 6ith naming c"n$enti"n S.nta1: s%nta9 !"r c"lumn le$el c"nstraints using primar% ke%( S72 V&R/T/ U+1D(TH)/VU+1D(NM/V ( &+2 NM/(0 UDTTH)/V (S-O/'&+NSTR-NTS UNM/ +G &+NSTR-NTSVUTH)/ +G &+NSTR-NTSV, &+2 NM/(2 UDTTH)/V (S-O/'XXXXXXXXXXX(XXXX'N Command: S72V&R/T/ T12/ /M)2+H// ( /M)N+ N#M1/R (:' CO(STR&(T EMPFEMP(OFP8 PRM&RH 8EH' /NM/.R&AR2 (00',D+1 .R&AR2 (6',S2 N#M1/R (;',D/)TN+ N#M1/R (<''N Ta$le le5el 2rimar. ke. con"traint": +%ERH: :? 70;( =rite a 8uer% t" create primar% c"nstraints 6ith ta3le le$el 6ith naming c"n$enti"n S.nta1: The s%nta9 !"r ta3le le$el c"nstraints using primar% ke% S72B V&R/T/ U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V (S-O/', &+2#MN NM/(0 UDTTH)/V (S-O/', &+NSTR-NTS UNM/ +G TA/ &+NSTR-NTSVUTH)/ +G TA/ &+NSTR-NTSV'N Command: S72V&R/T/ T12/ /M)2+H// (/M)N+ N#M1/R(6',/NM/ .R&AR2(20',D+1 .R&AR2(6', S2 N#M1/R(<', D/)TN+ N#M1/R(;', CO(STR&(T EMPFEMP(OFP8 PRM&RH 8EH/EMP(O00I Ta$le le5el con"traint with alter command /2rimar. ke.0: +%ERH: :@ 706( =rite a 8uer% t" create primar% c"nstraints 6ith alter c"mmand S.nta1: The s%nta9 !"r c"lumn le$el c"nstraints using primar% ke%( S72BV&R/T/ U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/', &+2#MN NM/(0 UDTTH)/V (S-O/''N TORU 83 S72V 2T/R T12/ UT12/ NM/V DD &+NSTR-NTS UNM/ +G TA/&+NSTR-NTSV UTH)/ +G TA/ &+NSTR-NTSVU&+2#MN NM/V'N Command: S72V&R/T/ T12/ /M)2+H//(/M)N+ N#M1/R(;',/NM/ .R&AR2(6',D+1 .R&AR2(6', S2 N#M1/R(6',D/)TN+ N#M1/R(6''N S72V2T/R T12/ /M)3 DD &+NSTR-NT EMP=FEMP(OFP8 PRM&RH8EH /EMP(O0I REFERE(CE 4FORE6( 8EH CO(STR&(T -t en!"rces relati"nship 3et6een ta3les( T" esta3lish parent-child relati"nship 3et6een 2 ta3les ha$ing a c"mm"n c"lumn de!initi"n, 6e make use "! this c"nstraint( T" implement this, 6e sh"uld de!ine the c"lumn in the parent ta3le as primar% ke% and same c"lumn in the child ta3le as !"reign ke% re!erring t" the c"rresp"nding parent entr%( Forei-n ke. c"lumn "r c"m3inati"n "! c"lumn included in the de!initi"n "! re!erential integrit%, 6hich 6"uld re!er t" a re!erenced ke%( Referenced ke. -t is a uni8ue "r primar% ke% up"n 6hich is de!ined "n a c"lumn 3el"nging t" the parent ta3le( Col#mn le5el forei-n ke. con"traint +%ERH: :A 7(0<( =rite a 8uer% t" create !"reign ke% c"nstraints 6ith c"lumn le$el Parent Ta$le: S.nta1: S%nta9 !"r &"lumn le$el c"nstraints #sing )rimar% ke% S72BV&R/T/ U+1D(TH)/VU+1D(NM/V ( &+2#MN NM/(0 UDTTH)/V(S-O/'UTH)/ +G &+NSTR-NTSV , &+2#MN NM/(0 UDTTH)/V (S-O/'XXXXXXXXX'N Command: S72V &R/T/ T12/ )EPT( )EPT(O N#M1/R(3' PRM&RH 8EH, )(&ME .R&AR2(20',,OC&TO( .R&AR2(0;''N Ta3le created( S72V desc D/)TN Name Null] T%pe ----------------- ---------------- -------------------- D/)TN+ N+T N#22 N#M1/R(3' DNM/ .R&AR2(20' 2+&T-+N .R&AR2(0;' S72V select Q !r"m D/)TN D/)TN+ DNM/ 2+&T-+N ------------ ---------------- --------------- 84 000 kamal chennai 002 ra@ini madurai 003 @ith k"$ai Child Ta$le: S.nta1: The s%nta9 !"r c"lumn le$el c"nstraints using !"reign ke%( S72BV&R/T/ U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/', &+2#MN NM/2 UDTTH)/V (S-O/' R/G/R/N&/S UT12/ NM/V(&+2#MN NM/V X('N Command: S72V &R/T/ T12/ EMP,(EMP(O N#M1/R(:', )EPT(O N#M1/R(3' REFERE(CES D/)T()EPT(O', )ES6( .R&AR2(00''N Ta3le created( S72V desc /M)2N Name Null] T%pe -------------------------- ------------- ---------------------------- /M)N+ N#M1/R(:' D/)TN+ N#M1/R(3' D/S-,N .R&AR2(00' S72V insert int" /M)2 $alues(;000,000,IRDI'N 0 r"6 created( S72V insert int" /M)2 $alues(;003,003,IKDI'N 0 r"6 created( S72V insert int" /M)2 $alues(;006,00:,IRMHI'N insert int" /M)2 $alues(;006,00:,IRMHI' Q /RR+R at line 0B +R-022?0B integrit% c"nstraint (SHST/M(SHSP&00002?:' $i"lated - parent ke% n"t !"und S72V select Q !r"m /M)2N /M)N+ D/)TN+ D/S-,N ---------- ------------ ------------- ;000 000 RD ;003 003 KD Col#mn le5el forei-n ke. con"traint with namin- con5er"ion" +%ERH: :B 7(0>( =rite a 8uer% t" create !"reign ke% c"nstraints 6ith c"lumn le$el Parent Ta$le: S.nta1: The s%nta9 !"r c"lumn le$el c"nstraints using primar% ke%( S72 BV &R/T/U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/'UTH)/ +G &+NSTR-NTSV,&+2#MN NM/(0 UDTTH)/V (S-O/'X'N Child Ta$le: S.nta1: "%nta9 !"r c"lumn le$el c"nstraints using !"reign ke%( S72 BV &R/T/U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/' , 85 &+2#MN NM/2 UDTTH)/V (S-O/' CO(STR&(T MCO(ST.(&MELR/G/R/N&/S UT12/ NM/V (&+2#MN NM/VX'N Command: S72V&R/T/ T12/ D/)T (D/)TN+ N#M1/R (2' PRM&RH8EH, DNM/ .R&AR2 (20', 2+&T-+N .R&AR2 (0;''N S72V&R/T/ T12/ /M): (/M)N+ N#M1/R (3', D/)TN+ N#M1/R (2' CO(STR&(T EMP>&F)EPT(OFF8 REFERE(CES )EPT /)EPT(O0' D/S-,N .R&AR2 (00''N Ta$le le5el forei-n ke. con"traint": +%ERH: :C 7(0?( =rite a 8uer% t" create !"reign ke% c"nstraints 6ith Ta3le le$el( Parent Ta$le: S.nta1: S72 BV &R/T/U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/' UTH)/ +G &+NSTR-NTSV, &+2#MN NM/(0 UDTTH)/V (S-O/'X'N Child Ta$le: S.nta1: The s%nta9 !"r ta3le le$el c"nstraints using !"reign ke%( S72 BV &R/T/U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/', &+2#MN NM/2 UDTTH)/V (S-O/', CO(STR&(T MCO(ST.(&MELR/G/R/N&/S UT12/ NM/V (&+2#MN NM/V'N Command: S72V&R/T/ T12/ D/)T(D/)TN+ N#M1/R(2' PRM&RH 8EH, DNM/ .R&AR2(20',2+&T-+N .R&AR2(0;''N S72V&R/T/ T12/ /M);(/M)N+ N#M1/R(3',D/)TN+ N#M1/R(2', D/S-,N .R&AR2(00' CO(STR&(T E(P<F)EPT(OFF8 FORE6(8EH/)EPT (O0 REFERE(CES )EPT/)EPT(O00I Ta$le le5el forei-n ke. con"traint" with alter command: +%ERH:<D 7(20( =rite a 8uer% t" create !"reign ke% c"nstraints 6ith Ta3le le$el 6ith alterc"mmand( Parent Ta$le: S.nta1: S72 BV&R/T/U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/'UTH)/ +G &+NSTR-NTSV , &+2#MN NM/(0 UDTTH)/V (S-O/' X((XXXXXXXXXXX'N Child Ta$le: S.nta1: The s%nta9 !"r ta3le le$el c"nstraints using !"reign ke%( S72BV&R/T/ U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/', &+2#MN NM/2 UDTTH)/V (S-O/''N 86 S.nta1: S72V 2T/R T12/ UT12/ NM/V DD &+NSTR-NT U&+NST( NM/VR/G/R/N&/S UT12/ NM/V (&+2#MN NM/V'N Command: S72V&R/T/ T12/ D/)T(D/)TN+ N#M1/R(2' )R-MRH K/H, DNM/ .R&AR2(20', 2+&T-+N .R&AR2 (0;''N S72V&R/T/ T12/ /M); (/M)N+ N#M1/R(3', D/)TN+ N#M1/R (2', D/S-,N .R&AR2 (00''N S72V2T/R T12/ /M)6 DD &+NSTR-NT /M)6PD/)TN+PGK G+R/-,NK/H(D/)TN+'R/G/R/N&/S D/)T(D/)TN+'N CHEC8 CO(STR&(T &heck c"nstraint can 3e de!ined t" all"6 "nl% a particular range "! $alues (6hen the manipulati"n $i"lates this c"nstraint, the rec"rd 6ill 3e re@ected( &heck c"nditi"n cann"t c"ntain su3 8ueries( Col#mn le5el check" con"traint: +%ERH: <: 7(20( =rite a 8uer% t" create &heck c"nstraints 6ith c"lumn le$el S.nta1: s%nta9 !"r c"lumn le$el c"nstraints using check( S72BV&R/T/ U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/' &+NSTR-NT U&+NSTR-NTS NM/VUTH)/ +G &+NSTR-NTSV(&+NSTR-TNS &R-T/R-' , &+2#MN NM/2 UDTTH)/V (S-O/''N Command: S72V&R/T/ T12/ /M)<(/M)N+ N#M1/R(3',/NM/ .R&AR2(20',D/S-,N .R&AR2(0;', S2 N#M1/R(;'CO(STR&(T /M)<PS2P&K &A/&K(S2V;00 NDS2U00000', D/)TN+ N#M1/R(2''N Ta$le ,e5el Check Con"traint: +%ERH: << 7(22( =rite a 8uer% t" create &heck c"nstraints 6ith ta3le le$el S.nta1: S%nta9 !"r Ta3le le$el c"nstraints using &heck( S72BV&R/T/ U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/', (&+2#MN NM/2 UDTTH)/V (S-O/', &+NSTR-NTU&+NSTR-NTS NM/VUTH)/ +G &+NSTR-NTSV (&+NSTR-TNS&R-T/R-''N Command: S72V&R/T/ T12/ /M)>(/M)N+ N#M1/R(3',/NM/ .R&AR2(20',D/S-,N .R&AR2(0;', S2 N#M1/R(;',D/)TN+ N#M1/R(2', CO(STR&(TS /M)>PS2P&K &A/&K(S2V;00 &()S2U00000''N Check Con"traint with <er Command: +%ERH:<= 7(23( =rite a 8uer% t" create &heck c"nstraints 6ith ta3le le$el using alter c"mmand( 87 S.nta1: S%nta9 !"r Ta3le le$el c"nstraints using &heck( S72BV&R/T/ U+1D(TH)/VU+1D(NM/V (&+2#MN NM/(0 UDTTH)/V(S-O/', (&+2#MN NM/2 UDTTH)/V (S-O/', &+NSTR-NTU&+NSTR-NTS NM/VUTH)/ +G &+NSTR-NTSV (&+NSTR-TNS&R-T/R-'' N Command: S72V&R/T/ T12/ /M)?(/M)N+ N#M1/R,/NM/ .R&AR2(20',D/S-,N .R&AR2(0;', S2 N#M1/R(;''N S72V2T/R T12/ /M)? DD CO(STR&(TS /M)?PS2P&KCHEC8(S2V;00 ND S2U00000'N %(+%E CO(STR&(T -t is used t" ensure that in!"rmati"n in the c"lumn !"r each rec"rd is uni8ue, as 6ith teleph"ne "r dri$ers license num3ers( -t pre$ents the duplicati"n "! $alue 6ith r"6s "! a speci!ied c"lumn in a set "! c"lumn( c"lumn de!ined 6ith the c"nstraint can all"6 null $alue( -! uni8ue ke% c"nstraint is de!ined in m"re than "ne c"lumn i(e(, c"m3inati"n "! c"lumn cann"t 3e speci!ied( Ma9imum c"m3inati"n "! c"lumns that a c"mp"site uni8ue ke% can c"ntain is 06( Col#mn ,e5el Con"traint: +%ERH:<> 7(2:( =rite a 8uer% t" create uni8ue c"nstraints 6ith c"lumn le$el S.nta1: s%nta9 !"r c"lumn le$el c"nstraints 6ith uni8ue( S72 BV &R/T/ U+1D(TH)/VU+1D(NM/V (U&+2#MN NM/(0V UDTTH)/V (S-O/' &+NSTR-NT UNM/ +G &+NSTR-NTSVU&+NSTR-NT TH)/V, (&+2#MN NM/2 UDTTH)/V (S-O/''N Command: S72V&R/T/ T12/ /M)00(/M)N+ N#M1/R(3',/NM/ .R&AR2(20', D/S,-N .R&AR2 (0;'CO(STR&(T /M)00PD/S-,NP#K #N-7#/, S2 N#M1/R (;''N Ta$le ,e5el Con"traint: +%ERH: <? 7(2;( =rite a 8uer% t" create uni8ue c"nstraints 6ith ta3le le$el S.nta1: s%nta9 !"r ta3le le$el c"nstraints 6ith uni8ue( S72 BV &R/T/ U+1D(TH)/VU+1D(NM/V (U&+2#MN NM/(0VUDTTH)/V (S-O/', (&+2#MN NM/2 UDTTH)/V (S-O/', &+NSTR-NTUNM/ +G &+NSTR-NTSVU&+NSTR-NT TH)/V(&+2#MN NM/'N' N Command: S72V&R/T/ T12/ /M)00(/M)N+ N#M1/R(3',/NM/ .R&AR2(20',D/S-,N .R&AR2(0;', S2 N#M1/R(;', &+NSTR-NT /M)00PD/S-,NP#K #N-,#/(D/S-,N''N Ta$le ,e5el Con"traint <er Command: +%ERH:<@ 7(26( =rite a 8uer% t" create uni8ue c"nstraints 6ith ta3le le$el S.nta1: s%nta9 !"r ta3le le$el c"nstraints 6ith check using alter( S72 BV &R/T/ U+1D(TH)/VU+1D(NM/V (U&+2#MN NM/(0VUDTTH)/V (S-O/', (U&+2#MN NM/(2VUDTTH)/V (S-O/'' N 88 S72V 2T/R T12/ DD U&+NSTR-NTSVU&+NSTR-NTS NM/VU&+NSTR-NTS TH)/V (&+2#MN NM/'N Command: S72V&R/T/ T12/ /M)02(/M)N+ N#M1/R(3',/NM/ .R&AR2(20',D/S-,N .R&AR2(0;', S2 N#M1/R(;''N S72V2T/R T12/ /M)02 DD &+NSTR-NT /M)02PD/S-,NP#K#N-7#/(D/S-N,'N (OT (%,, CO(STR&(TS =hile creating ta3les, 3% de!ault the r"6s can ha$e null $alue (the en!"rcement "! n"t null c"nstraint in a ta3le ensure that the ta3le c"ntains $alues( Col#mn ,e5el Con"traint: +%ERH: <A 7(2<( =rite a 8uer% t" create N"t Null c"nstraints 6ith c"lumn le$el S.nta1: s%nta9 !"r c"lumn le$el c"nstraints 6ith n"t null S72 BV &R/T/ U+1D(TH)/VU+1D(NM/V(U&+2#MN NM/(0VUDTTH)/V (S-O/' &+NSTR-NT UNM/ +G &+NSTR-NTSV U&+NSTR-NT TH)/V, (&+2#MN NM/2 UDTTH)/V (S-O/'' N Command: S72V&R/T/ T12/ /M)03(/M)N+ N#M1/R(:', /NM/ .R&AR2(20' &+NSTR-NT /M)03P/NM/PNN N+T N#22, D/S-,N .R&AR2(20',S2 N#M1/R(3''N (%,, CO(STR&(TS Setting null $alue is appr"priate 6hen the actual $alue is unkn"6n, "r 6hen a $alue 6"uld n"t 3e meaning!ul( null $alue is n"t e8ui$alent t" a $alue "! Fer"( null $alue 6ill al6a%s e$aluate t" null in an% e9pressi"n( =hen a c"lumn name is de!ined as n"t null, that c"lumn 3ec"mes a mandat"r% i(e(, the user has t" enter data int" it( N"t null -ntegrit% c"nstraint cann"t 3e de!ined using the alter ta3le c"mmand 6hen the ta3le c"ntain r"6s( Col#mn ,e5el Con"traint: +%ERH:<B 7(2>( =rite a 8uer% t" create Null c"nstraints 6ith c"lumn le$el S.nta1: s%nta9 !"r c"lumn le$el c"nstraints 6ith null S72 BV &R/T/ U+1D(TH)/VU+1D(NM/V ( U&+2#MN NM/(0VUDTTH)/V (S-O/' CO(STR&(T UNM/ +G &+NSTR-NTSV U&+NSTR-NT TH)/V,(&+2#MN NM/2 UDTTH)/V (S-O/'' N 89 Command: S72V&R/T/ T12/ /M)03(/M)N+ N#M1/R(:', /NM/ .R&AR2(20' &+NSTR-NT /M)03P/NM/PNN N#22, D/S-,N .R&AR2(20',S2 N#M1/R(3''N )EF&%,T CO(STR&(TS De!ault c"nstraints assign the de!ault $alues i! the $alues is n"t passed at the time "! inserting the $alues t" the ta3le +%ERH:<B 7(2>( =rite a 8uer% t" create de!ault c"nstraints 6ith c"lumn le$el S.nta1: s%nta9 !"r c"lumn le$el c"nstraints 6ith de!ault S72 BV &R/T/ U+1D(TH)/VU+1D(NM/V ( U&+2#MN NM/(0VUDTTH)/V (S-O/' , U&+2#MN NM/(2 UDTTH)/V (S-O/' )efa#lt Udefa#lt 5al#eV' N Command: S72V &R/T/ T12/ DG( R/,N+ N#M1/R(;', NM/ .R&AR2(20', MRKS N#M1/R(3' )EF&%,T ?? 'N Ta3le created( S72V -NS/RT -NT+ DG .2#/S(0000,IRD#NI,N#22'N 0 r"6 created( S72V -NS/RT -NT+ DG(R/,N+' .2#/S(:DD?'N 0 r"6 created( S72V -NS/RT -NT+ DG .2#/S(0000,IRDI,<>'N 0 r"6 created( S72V S/2/&T Q GR+M DGN R/,N+ NM/ MRKS ----------- ---------- ------------ 0000 RD#N 000; ;; 90 0000 RD <> )S&B,(6 &() )ROPP(6 CO(STR&(TS %S(6 )S&B,E4E(&B,E =hene$er a c"nstraint is created !"r a c"lumn(s', e$er% time an entr% is made t" the c"lumn , it must 3e e$aluated t" determine 6hether the $alue is all"6ed in that c"lumn(it checks d"esnLt .i"late the c"nstraint'( -! a large 3l"ck "! data is 3eing added t" a ta3le the $alidati"n pr"cess can se$erel% sl"6 d"6n the "racle ser$erLs pr"cessing speed( H"u are certain that the data 3eing added t" a ta3le adheres t" the c"nstraints then disa3le the c"nstraints 6hile adding that particular 3l"ck "! data "! data t" the ta3le( T" D-S12/ a c"nstraint, issue an 2T/R T12/ c"mmand and change the status "! the c"nstraint t" D-S12/( t a later time can reissue the 2T/R T12/ c"mmand and change the status "! the c"nstraint 3ack t" /N12/ S"metimes, temp"raril% disa3le "r dr"p a c"nstraint( Con"traint )i"a$le +%ERH:<C 7(2?( =rite a 8uer% t" disa3le the c"nstraints S.nta1: S%nta9 !"r disa3ling a single c"nstraint in a ta3le( S72V2T/R T12/ UT12/-NM/V D-S12/ &+NSTR-NT U&+NSTR-NTNM/V S72V2T/R T12/ /M)03 D-S12/ &+NSTR-NT /M)03P/NM/PNNN#22N Con"traint Ena$le +%ERH: =D 7(30( =rite a 8uer% t" ena3le the c"nstraints S.nta1: S.nta1 for di"a$lin- a "in-le con"traint in a ta$le: S72V2T/R T12/ UT12/-NM/V D-S12/ &+NSTR-NT U&+NSTR-NTNM/V Command: S72V2T/R T12/ /M)03 /N12/ &+NSTR-NT /M)03P/NM/PNN N#22N TO ,ST &,, THE CO(STR&(TS: S72VS/2/&T Q GR+M #S/RP&+NSTR-NTSN S72V S/2/&T &+NSTR-NTPNM/,&+NSTR-NTPTH)/,STT#S GR+M #S/RP&+NSTR-NTSN &+NSTR-NTPNM/ & STT#S ------------------------------ - -------- SHSP&00006;2 ) /N12/D SHSP&00006;; # /N12/D SHSP&00006;> ) D-S12/D 0: r"6s selected( S72Vselect c"nstraintPname,c"nstraintPt%pe,status GR+M #S/RP&+NSTR-NTS =A/R/ T12/PNM/S1& RES%,T: 91 Thus the S72 c"mmands !"r &reating an /mpl"%ee data3ase t" set $ari"us c"nstraints has 3een $eri!ied and e9ecuted success!ull%( CRE&T(6 RE,&TO(SHP BET9EE( THE )&T&B&SES ( R)BMS E1: (o: D? /?.:0 TO MP,EME(T&TO( OF SET OPER&TORS FF : FF : FF &M: T" /9ecute and $eri!% The S72 &"mmands G"r Set +perat"rs -mplementati"n -n Relati"nal M"del ( OBJECT!E: Set "perat"rs are used t" retrie$e the data !r"m t6" "r multiple ta3les( The% are di!!erent t%pes( #ni"n #ni"n all -ntersect Minus &,6ORTHM: STEP :: Start STEP <: &reate t6" di!!erent ta3les 6ith its essential attri3utes( STEP =: -nsert attri3ute $alues int" the ta3les( STEP >: &reate the result !"r the $ari"us set "perati"n( STEP ?: /9ecute &"mmand and e9tract in!"rmati"n !r"m the ta3les( STEP @B St"p S&MP,E T&B,ES S72V select Q !r"m ST#D/NTP-TN R/,PN+ NM/ 1RN& S#1D/&T ------------ --------------- ----------- -------- 00000 ram -T DT STR#&T#R/ 00002 Sam -T DT1S/ SHST/M 00003 Tam -T =/1 T/&AN+2+,H 0000: RD -T DS) 0000; TD -T D-) 00006 khan -T =/1 T/&AN+2+,H 3000; RD /&/ &-R&#-T D/S-,N < r"6s selected( S72V select Q !r"m ST#D/NTP/&/N R/,PN+ NM/ 1RN& S#1D/&T ------------ ---------------- ---- ----- -------------------- 30000 RM# /&/ D-) 30002 SM# /&/ DS) 30003 TM# /&/ &-R&#-T D/S-,N 92 3000: RD# /&/ /2/&TR+ M/&AN-&S 3000; RD /&/ &-R&#-T D/S-,N 3000; RD /&/ &-R&#-T D/S-,N %(O( This 6ill c"m3ine the rec"rds "! multiple ta3les ha$ing the same structure( E1: S72V select Q !r"m studentP-T uni"n select Q !r"m studentP/&/N R/,PN+ NM/ 1RN& S#1D/&T ----------- -------- ----------- ------------------ 00000 ram -T DT STR#&T#R/ 00002 Sam -T DT1S/ SHST/M 00003 Tam -T =/1 T/&AN+2+,H 0000: RD -T DS) 0000; TD -T D-) 00006 khan -T =/1 T/&AN+2+,H 30000 RM# /&/ D-) 30002 SM# /&/ DS) 30003 TM# /&/ &-R&#-T D/S-,N 3000: RD# /&/ /2/&TR+ M/&AN-&S 3000; RD /&/ &-R&#-T D/S-,N 00 r"6s selected( %(O( &,, This 6ill c"m3ine the rec"rds "! multiple ta3les ha$ing the same structure 3ut including duplicates( E1: S72V select Q !r"m studentP-T uni"n all select Q !r"m studentP/&/N R/,PN+ NM/ 1RN& S#1D/&T ------------- ----------- ----------- -------------------- 00000 ram -T DT STR#&T#R/ 00002 Sam -T DT1S/ SHST/M 00003 Tam -T =/1 T/&AN+2+,H 0000: RD -T DS) 0000; TD -T D-) 00006 khan -T =/1 T/&AN+2+,H 3000; RD /&/ &-R&#-T D/S-,N 30000 RM# /&/ D-) 30002 SM# /&/ DS) 30003 TM# /&/ &-R&#-T D/S-,N 3000: RD# /&/ /2/&TR+ M/&AN-&S 3000; RD /&/ &-R&#-T D/S-,N 3000; RD /&/ &-R&#-T D/S-,N 03 r"6s selected( (TERSECT This 6ill gi$e the c"mm"n rec"rds "! multiple ta3les ha$ing the same structure( E1: S72V select Q !r"m studentP-T -NT/RS/&T select Q !r"m studentP/&/N R/,PN+ NM/ 1RN& S#1D/&T ------------ --------- ----------- ----------------- 93 3000; RD /&/ &-R&#-T D/S-,N M(%S This 6ill gi$e the rec"rds "! a ta3le 6h"se rec"rds are n"t in "ther ta3les ha$ing the same structure( E1: S72V select Q !r"m studentP-T M-N#S select Q !r"m studentP/&/N R/,PN+ NM/ 1RN& S#1D/&T ------------ ---------- ---------- ------------------- 00000 ram -T DT STR#&T#R/ 00002 Sam -T DT1S/ SHST/M 00003 Tam -T =/1 T/&AN+2+,H 0000: RD -T DS) 0000; TD -T D-) 00006 khan -T =/1 T/&AN+2+,H 6 r"6s selected( RES%,T: Thus the S72 c"mmands !"r S/T "perat"rs has 3een $eri!ied and e9ecuted success!ull%( 94 CRE&T(6 RE,&TO(SHP BET9EE( THE )&T&B&SES ( R)BMS E1: (o: D? /?.<0 To im2lementation of (e"ted +#erie" FF : FF : FF &M: T" e9ecute and $eri!% the S72 c"mmands !"r Nested 7ueries( OBJECT!E: Nested 7uer% can ha$e m"re than "ne le$el "! nesting in "ne single 8uer%( S72 nested 8uer% is a S/2/&T 8uer% that is nested inside a S/2/&T, #)DT/, -NS/RT, "r D/2/T/ S72 8uer%( &,6ORTHM: STEP :: Start the pr"gram( STEP <: &reate t6" di!!erent ta3les 6ith its essential attri3utes( STEP =: -nsert attri3ute $alues int" the ta3le( STEP >: &reate the Nested 8uer% !r"m the a3"$e created ta3le( STEP ?: /9ecute &"mmand and e9tract in!"rmati"n !r"m the ta3les( STEP @: St"p the pr"gram( Table - 95 S.nta1: s%nta9 !"r creating a ta3le. S72B &R/T/ U+1D(TH)/V U+1D(NM/V (&+2#MN NM/(0 UDTTH)/V (S-O/', &+2#MN NM/(0 UDTTH)/V (S-O/' X'N Command: S72V &R/T/ T12/ /M)2(/M)N+ N#M1/R(;',/NM/ .R&AR2(20',D+1 .R&AR2(20', S2 N#M1/R(6',M,RN+ N#M1/R(:',D/)TN+ N#M1/R(3''N S.nta1: s%nta9 !"r insert rec"rds in t" a ta3le( S72 BV -NS/RT -NT+ UT12/ NM/V .2#/SU .20, L.22M,X(('N Command: S72V S/2/&T QGR+M /M)2N /M)N+ /NM/ D+1 S2 M,RN+ D)TN+ ----------- ---------- ------- ------------ ---------- ---------- 0000 MA/SA )R+,RMM/R 0;000 0;60 200 0002 MN+D T/ST/R 02000 0;60 200 0003 KRTA-K )R+,RMM/R 03000 0:00 200 000: NR/SA &2/RK 0:00 0:00 200 000; MN- T/ST/R 03000 0:00 200 0006 .-K- D/S-,N/R 02;00 0;60 200 000< M+AN D/S-,N/R 0:000 0;60 200 000> N.//N &R/T-+N 20000 0:00 200 000? )RSD D-R 20000 0;60 202 0000 ,N/SA D-R 0;000 0:00 200 T&B,E3 < S.nta1: s%nta9 !"r creating a ta3le( S72B &R/T/ U+1D(TH)/V U+1D(NM/V (&+2#MN NM/(0 UDTTH)/V (S-O/', &+2#MN NM/(0 UDTTH)/V (S-O/' XXXXXXN Command: S72V &R/T/ T12/ D/)T2(D/)TN+ N#M1/R(3',D/)TNM/ .R&AR2(00', 2+&T-+N .R&AR2(0;''N Ta3le created( S.nta1: s%nta9 !"r insert rec"rds in t" a ta3le( S72 BV -NS/RT -NT+ UT12/ NM/V .2#/SU .20, L.22M,X(('N S72V S/2/&T QGR+M D/)T2N D/)TN+ D/)TNM/ 2+&T-+N ---------- ---------- --------------- 00< D/./2+) DHR 200 D/1#, #K 200 T/ST #S 200 T/ST #SSR 00> D/1#, DHR 00? 1#-2D )+TA/R- 6 r"6s selected( S.nta1: 6E(ER&, SH(T&7 FOR (ESTE) +%ERH: 96 S+,L S/2/&T R&+2#MNPNM/0R GR+M RT12/PNM/0R =A/R/ R&+2#MNPNM/2R Y&+M)R-S+N +)/RT+RZ (S/2/&T R&+2#MNPNM/3R GR+M RT12/PNM/2R =A/R/ Y&+ND-T-+NZ' S.nta1: s%nta9 nested 8uer% statement( S+,L S/2/&T U&+2#MNPNM/V GR+M GR+RM UT12/ P0V =A/R/ U&+2#MNPNM/V UR/2T-+N2 P+)/RT-+NV L.2#/M (S/2/&T (,,R/&T/ G#N&T-+N' GR+M UT12/P0V =A/R/ U&+2#MN NM/V S L.2#/M (S/2/&T U&+2#MNPNM/V GR+M UT12/P2V =A/R/ U&+2#MNPNM/S L.2#/M''N (ESTE) +%ERH ST&TEME(T: Command: S+,L S/2/&T /NM/ GR+M /M)2 =A/R/ S2V(S/2/&T M-N(S2' GR+M /M)2 =A/R/ D)TN+S(S/2/&T D/)TN+ GR+M D/)T2 =A/R/ 2+&T-+NSI#KI''N (e"ted +#er. O#t2#t: /NM/ ---------- MA/SA MN+D KRTA-K MN- .-K- M+AN N.//N )RSD ,N/SA RES%,T: Thus the S72 c"mmands !"r t" implementati"n "! nested 8ueries has 3een $eri!ied and e9ecuted success!ull%( CRE&T(6 RE,&TO(SHP BET9EE( THE )&T&B&SES ( R)BMS 97 E1: (o: D? /?.=0 To im2lementation the Join O2eration" FF : FF : FF &M: T" e9ecute and $eri!% the S72 c"mmands !"r $ari"us @"in "perati"n( &,6ORTHM: STEP :: Start the pr"gram( STEP <: &reate t6" di!!erent ta3les 6ith its essential attri3utes( STEP =: -nsert attri3ute $alues int" the ta3le( STEP >: &reate the ta3le "3@ect !"r eas% re!erence( STEP ?: D"in t6" ta3les 3% using D+-N "perat"r( STEP @: Displa% the result "! the result ta3le( STEP A: St"p the pr"gram( JO(SB D"ins are used t" retrie$e the data !r"m multiple ta3les( T.2e" of Join"B 0( /7#-PD+-N 2( N+N /7#-PD+-N 3( S/2G D+-N :( +#T/R D+-N :(0 Right "uter @"in :(2 2e!t "uter @"in :(3 Gull "uter @"in 0( E+%FJO(B =hen ta3les are @"ined 3asing "n a c"mm"n c"lumn it is called /7#-PD+-N( 98 E1B select empn", ename, dname !r"m emp, dept 6here emp(deptn" S dept(deptn"N EMPNO ENAME DNAME 7369 SMITH RESEARCH 7499 ALLEN SALES 7521 WARD SALES (oteB =e need t" menti"n @"in c"nditi"ns in the 6here clause( -n /7#-PD+-NS 6e al"ng use t" e8ual t" "perat"r in @"in c"nditi"n( E1B SQL6S$#$t$ $04no2 $n!0$2 s!#2 7o"2 8n!0$2 #oc 9%o0 $042 8$4t /&$%$ $04:8$4tno ; 8$4t:8$4tno5 SQL6Selete empn", ename, sal, deptn", dname, l"c !r"m emp, dept 6here emp(deptn" S dept(deptn"N44 err"r SQL6Selete empn", ename, sal, emp(deptn", dname, l"c !r"m emp, dept 6here emp(deptn" S dept(deptn"N 44$alid (oteB 6e need t" menti"n ta3le name d"t c"lumn(emp(deptn"' name !"r the c"mm"n c"lumn t" res"l$e the an% ta3le( The c"mm"n c"lumn can 3e retrie$ed !r"m an% "! the ta3le( =e can !ilter the data !r"m the result "! @"in( E1B SQL6Select empn", ename, sal, emp(deptn", dname, l"c !r"m emp, dept 99 6here emp(deptn" S dept(deptn" ND sal V 2000N T" impr"$e the per!"rmance "! the @"in 6e need menti"n ta3le name d"t c"lumn name !"r all the c"lumns( E1B SQL6Select emp(empn", emp(ename, emp(sal,emp(deptn", dept(dname, dept(l"c !r"m emp,dept 6here emp(deptn" S dept(deptn" ND sal V 2000N Ta$le alia"B Ta3le alias is an alternate name gi$en t" a ta3le( 1% using a ta3le alias length "! the ta3le reduces and at the same time per!"rmance is maintains( Ta3le alias are create in same clause can 3e used in select clause as 6ell as 6here clause( Ta3le alias is temp"rar% "nce the 8uer% is e9ecuted the ta3le alias are l"sed( E1B SQL6Select /(/mpn", /(/name, /(sal, /(deptn", D(Dname, D(l"c !r"m emp /, Dept D 6here /(deptn" S D(deptn"N Join the m#lti2le ta$le"/= ta$le"0B Select Q !r"m reasN Cit. State Ne6%"rk ) Dallas Mh E1B SQL6Select /(empn", /(ename, /(sal,D(dname,(state !r"m emp /, dept D, reas 6here /(deptn" S D(deptn" ND D(l"c S (cit%N (oteB T" @"in LnM ta3les 6e need n-0 c"nditi"ns( (O( E+% JO(B =hen 6e d" n"t use N+N /7#- D+-N t" "perat"r in the @"in c"nditi"n is N+N /7#- D+-N( E1B 100 SQL6Select Q !r"m S2,RD/N ,RD/ 2+S2 A-S2 0 <00 0200 2 0200 0:00 3 0:00 2000 : 2000 3000 ; 3000 ???? SQL6Select e(empn", e(ename, e(sal, s(grade !r"m emp e, salgrade s 6here e(sal 1/T=//N s(l"sal ND hisalN /M)N+ /NM/ ,RD/ <36? SM-TA 0 <><6 DMS 0 <?00 DM/S 2 SQL6Select e(empn", e(ename, s(grade !r"m emp e, salgrade s 6here e(sal 1/T=//N s(l"sal ND s(hisal ND s(grade S :N SE,F JO(B =hen a ta3le is @"ining t" it sel! it is called sel! @"in( -n sel! @"ins 6e need t" create t6" ta3le aliases !"r the same ta3le( SQL6Select empn", ename, @"3, mgr, !r"m empN SQL6Select e(empn", e(ename, e(@"3, m(ename !r"m emp e, emp m 6here e(mgr S m(empn"N Em2no Ename Jo$ Ename <?02 G+RD N2HST D+N/S <>6? S&+TT &2/RK D+N/S <?00 DM/S S2/SMN 12K/ C&RTES&( PRO)%CTB =hen ta3les are @"ined 6ith"ut an% @"in c"nditi"n it is called &artesian pr"duct( -n the result 6e get all p"ssi3le c"m3inati"n( SQL6Select e(empn", e(ename, e(sal, e(deptn", d(dname, d(l"c 101 !r"m emp e, dept dN 440:Q:S;6 r"6s are selected &(S JO(SB The% are the three t%pes( ((ER JO(SB -t is same as /8ui @"in( E1B SQL6Select e(empn", e(ename, e(sal, e(deptn", d(dname, d(l"c !r"m emp e -NN/R D+-N dept d +N(e(deptn" S d(deptn"'N 2((&T%R&, JO(B -t is same as /8ui @"in( E1B SQL6Select empn", ename, sal, deptn", dname,l"c !r"m NT#R2 D+-N deptN CROSS PRO)%CT4CROSS JO(B -t is same as &artesian pr"duct( E1B SQL6Select e(empn", e(ename, e(sal, e(deptn", d(dname, d(l"c !r"m emp e &R+SS D+-N dept dN 440:Q: S ;6 r"6s are displa%ed( )EF&%,TB E1B SQL6&reate ta3le stu0(sn" num3er(3', Sname $archar2(00', Marks num3er(3' de!ault 000, D"@ Date D/G#2T s%sdate'N
SQL6-nsert int" stu0(sn", sname' $alues(000,MmalliM'N SQL6-nsert int" stu0 $alues(002,MR#NM,:0,M00-DN-0?M'N SQL6-nsert int" stu0 $alues (003,MK-RNM,N#22,M02-G/1-00M'N SN+ SNM/ MRKS D+D 102 000 malli 000 26-D#N-02 002 R#N :0 00-DN-0? 003 K-RN 02-G/1-00 S%PER 8EHB &"m3inati"n "! c"lumns 6hich can 3e used uni8ue ke% identi!% e$er% r"6 is called as super ke%( Ta3le "3@ect &"lumn ttri3utes R"6 Tuple4Rec"rd O%TER JO(SB -t is e9tensi"n "! /7#- D+-NS( -n "uter @"ins 6e get match as 6ell as n"n matching r"6s( (C' This called as "uter @"in "perat"r( :. R6HT O%TER JO(B S+, S.nta1B SQL6Select e(empn", e(ename, e(sal, e(deptn", d(dname, d(l"c !r"m emp e, dept d 6here e(deptn"(C' S d(deptn"N 440: C 0 S 0; r"6s em2no ename "al de2tno dname loc <?00 @ames ?;0 30 sales chicag" >?63 adams 0:00 20 clerk ne6%"rk 6<?> adams 2000 00 sales india &(S SH(T&7 OF R6HT O%TER JO(B NS- SHSTEB SQL6Select e(empn", e(ename, e(sal, e(deptn", d(dname, d(l"c !r"m emp e R-,AT +#T/R D+-N dept d +N(e(deptn" S d(deptn"'N ,EFT O%TER JO(B S+, S.nta1B SQL6Select e(empn", e(ename, e(sal, e(deptn", d(dname, d(l"c !r"m emp e, dept d 103 6here e(deptn" S d(deptn"(C'N 440:C3 S 0< r"6 displa%ed &(S SH(T&7 OF ,EFT O%TER JO(B &(S SH(T&7: SQL6Select e(empn", e(ename, e(sal, e(deptn", d(dname, d(l"c !r"m emp e 2/GT +#T/R D+-N dept d +N(e(deptn" S d(deptn"'N F%,, O%TER JO(B &(S SH(T&7B SQL6Select e(empn", e(ename, e(sal, e(deptn", d(dname, d(l"c !r"m emp e G#22 +#T/R D+-N dept d +N(e(deptn" S d(deptn"'N 440: C 2 C 3 S 0? r"6s are displa%ed( RES%,T: Thus the S72 c"mmands to implementati"n the @"in "perati"ns has 3een $eri!ied and e9ecuted success!ull%( St#d. of P,4S+, $lock. E1: (o: D@ FF : FF : FF 104 &M: T" 6rite a )24S72 3l"ck using di!!erent c"ntr"l (i!, i! else, !"r l""p, 6hile l""p,X' statements( OBJECT!E: )24S72 &"ntr"l Structure pr"$ides c"nditi"nal tests, l""ps, !l"6 c"ntr"l and 3ranches that let t" pr"duce 6ell-structured pr"grams P,4S+, )24S72 is +racleMs pr"cedural language e9tensi"n t" S72( )24S72 all"6s %"u t" mi9 S72 statements 6ith pr"cedural statements like -G statement, 2""ping structures etc( -t is e9tensi"n "! S72 the !"ll"6ing "r ad$antages "! )24S72( 0( =e can use pr"gramming !eatures like i! statement l""ps etc( 2( )24S72 helps in reducing net6"rk tra!!ic( 3( =e can ha$e user de!ined err"r massages 3% using c"ncept "! e9cepti"n handling( :( =e can per!"rm related acti"ns 3% using c"ncept "! Triggers( ;( =e can sa$e the s"urce c"de permanentl% !"r repeated e9ecuti"n( P,4S+, Block: )24S72 pr"grams called as )24S72 3l"ck( P,4S+, Block: D/&2R/ Declarati"n "! $aria3le Declarati"n "! curs"r ----------(+)T-+N2' Declarati"n "! e9cepti"n 105 1/,-N /9ecuta3le c"mmands --------- (MNDT+RH' /E&/)T-+N /9cepti"n handlers ----------(+)T-+N2' /NDN 4 T" e9ecute the pr"gram 4 c"mmand )eclare: This secti"n is used t" declare l"cal $aria3les, curs"rs, /9cepti"ns and etc( This secti"n is "pti"nal( E1ec#ta$le Section: This secti"n c"ntains lines "! c"de 6hich is used t" c"mplete ta3le( -t is mandat"r%( E1ce2tion Section: This secti"n c"ntains lines "! c"de 6hich 6ill 3e e9ecuted "nl% 6hen e9cepti"n is raised( This secti"n is "pti"nal( Sim2le"t P,4S+, Block: 1egin -------- -------- -------- /NDN SER!ERO%TP%T This 6ill 3e used t" displa% the "utput "! the )24S72 pr"grams( 1% de!ault this 6ill 3e "!!( S.nta1: Set ser$er"utput "n ^ "!! E1: S72V set ser$er"utput "n B,OC8 THPES n"n%m"us 3l"cks Named 3l"cks 2a3eled 3l"cks Su3pr"grams 106 Triggers &(O(HMO%S B,OC8S n"n%m"us 3l"cks implies 3asic 3l"ck structure( E1: 7 B pr"gram t" displa% the string JK 1/,-N D1MSP+#T)#T()#TP2-N/(LM. fir"t 2ro-ram*'B /NDN 4 ,&BE,E) B,OC8S 2a3eled 3l"cks are an"n%m"us 3l"cks 6ith a la3el 6hich gi$es a name t" the 3l"ck( E1: UUm%P3l""ckVV 1/,-N D3msP"utput(putPline(LM% !irst pr"gramM'B /NDN S%BPRO6R&MS Su3pr"grams are pr"cedures and !uncti"ns( The% can 3e st"red in the data3ase as stand-al"ne "3@ects, as part "! package "r as meth"ds "! an "3@ect t%pe( TR66ERS Triggers c"nsist "! a )24S72 3l"ck that is ass"ciated 6ith an e$ent that "ccurs in the data3ase( (ESTE) B,OC8S 3l"ck can 3e nested 6ithin the e9ecuta3le "r e9cepti"n secti"n "! an "uter 3l"ck( )E(TFERS -denti!iers are used t" name )24S72 "3@ects, such as $aria3les, curs"rs, t%pes and su3pr"grams( -denti!iers c"nsists "! a letter, "pti"nall% !"ll"6ed 3% an% se8uence "! characters, including letters, num3ers, d"llar signs, undersc"res, and p"und signs "nl%( The ma9imum length !"r an identi!ier is 30 characters( +%OTE) )E(TFERS -! %"u 6ant t" make an identi!ier case sensiti$e, include characters such as spaces "r use a reser$ed 6"rd, %"u can encl"se the identi!ier in d"u3le 8u"tati"n marks( E1: D/&2R/ 107 RaR num3er BS ;N RR num3er BS 6N 1/,-N d3msP"utput(putPline(Qa V Q ^^ a'N d3msP"utput(putPline(Q& V Q ^^ 'N /NDN 4 O#t2#t: a S 6 S 6 COMME(TS &"mments impr"$e reada3ilit% and make %"ur pr"gram m"re understanda3le( The% are ign"red 3% the )24S72 c"mpiler( There are t6" t%pes "! c"mments a$aila3le( Single line c"mments 108 Multiline c"mments S(6,E ,(E COMME(TS single-line c"mment can start an% p"int "n a line 6ith t6" dashes and c"ntinues until the end "! the line( E1: 1/,-N D3msP"utput(putPline(Lhell"M'N 33 "am2le 2ro-ram /NDN 4 M%,T,(E COMME(TS Multiline c"mments start 6ith the 4Q delimiter and ends 6ith Q4 delimiter( E1: 1/,-N D3msP"utput(putPline(Lhell"M'N 4P "am2le 2ro-ram P4 /NDN 4 !&R&B,E )EC,ER&TO(S .aria3les can 3e declared in declarati$e secti"n "! the 3l"ckN E1: D/&2R/ a n#m$erI $ n#m$er :V ?I c n#m$er defa#lt @I CO(ST&(T )EC,ER&TO(S T" declare a c"nstant, %"u include the &+NSTNT ke%6"rd, and %"u must suppl% a de!ault $alue( E1: D/&2R/ 3 con"tant num3er BS ;N 109 c con"tant num3er de!ault 6N (OT (%,, C,&%SE H"u can als" speci!% that the $aria3le must 3e n"t null( E1: D/&2R/ 3 c"nstant num3er not n#llBS ;N c num3er n"t null defa#lt @N &(CHORE) )EC,ER&TO(S )24S72 "!!ers t6" kinds "! anch"ring( Scalar anch"ring Rec"rd anch"ring SC&,&R &(CHOR(6 #se the _TH)/ attri3ute t" de!ine %"ur $aria3le 3ased "n ta3leMs c"lumn "! s"me "ther )24S72 scalar $aria3le( E1: D/&2R/ dn" de2t.de2tnoRt.2eI Su3t%pe tPnum3er is num3erN a tPnum3erN Su3t%pe tPsn" is "t#dent."noRt.2eI .Psn" tPsn"N RECOR) &(CHOR(6 #se the _R+=TH)/ attri3ute t" de!ine %"ur rec"rd structure 3ased "n a ta3le( E1: D/&2R/ .Pdept de2tRrowt.2eI 110 Benefit" of &nchored )eclaration" S%nchr"niFati"n 6ith data3ase c"lumns( N"rmaliFati"n "! l"cal $aria3les( PRO6R&MMER3)EF(E) THPES =ith the S#1TH)/ statement, )24S72 all"6s %"u t" de!ine %"ur "6n su3t%pes "r aliases "! prede!ined datat%pes, s"metimes re!erred t" as a3stract datat%pes( There are t6" kinds "! su3t%pes( &"nstrained #nc"nstrained CO(STR&(E) S%BTHPE su3t%pe that restricts "r c"nstrains the $alues n"rmall% all"6d 3% the datat%pe itsel!( E1: Su3t%pe p"siti$e is 3inar%Pinteger range 0((20:<:>36:<N -n the a3"$e declarati"n a $aria3le that is declared as p"siti$e can st"re "nl% ingeger greater than Fer" e$en th"ugh 3inar%Pinteger ranges !r"m -20:<:>36:<((C20:<:>36:<( %(CO(STR&(E) S%BTHPE su3t%pe that d"es n"t restrict the $alues "! the "riginal datat%pe in $aria3les declared 6ith the su3t%pe( E1: Su3t%pe !l"at is num3erN )&T&THPE CO(!ERSO(S )24S72 can handle c"n$ersi"ns 3et6een di!!erent !amilies am"ng the datat%pes( &"n$ersi"n can 3e d"ne in t6" 6a%s( /9plicit c"n$ersi"n -mplicit c"n$ersi"n 111 E7P,CT CO(!ERSO( This can 3e d"ne using the 3uilt-in !uncti"ns a$aila3le( MP,CT CO(!ERSO( )24S72 6ill aut"maticall% c"n$ert 3et6een datat%pe !amilies 6hen p"ssi3le( E1: D/&2R/ a $archar(00'N 1/,-N select deptn" int" a !r"m dept 6here dnameSI&&+#NT-N,IN /NDN -n the a3"$e $aria3le a is char t%pe and deptn" is num3er t%pe e$en th"ugh, "racle 6ill aut"maticall% c"n$erts the numeric data int" char t%pe assigns t" the $aria3le( )24S72 can aut"maticall% c"n$ert 3et6een &haracters and num3ers &haracters and dates !&R&B,E SCOPE &() !SB,TH The sc"pe "! a $aria3le is the p"rti"n "! the pr"gram in 6hich the $aria3le can 3e accessed( G"r )24S72 $aria3les, this is !r"m the $aria3le declarati"n until the end "! the 3l"ck( =hen a $aria3le g"es "ut "! sc"pe, the )24S72 engine 6ill !ree the mem"r% used t" st"re the $aria3le( The $isi3ilit% "! a $aria3le is the p"rti"n "! the pr"gram 6here the $aria3le can 3e accessed 6ith"ut ha$ing t" 8uali!% the re!erence( The $isi3ilit% is al6a%s 6ithin the sc"pe( -! it is "ut "! sc"pe, it is n"t $isi3le( 112 E1:: D/&2R/ a num3erN 33 "co2e of a 1/,-N -------- D/&2R/ 3 num3erN 33 "co2e of $ 1/,-N ----- /NDN ------ /NDN E1<: D/&2R/ a num3erN 3 num3erN 1/,-N 33 a ' $ a5aila$le here D/&2R/ 3 char(00'N 1/,-N 33 a and char t.2e $ i" a5aila$le here /NDN ----- /NDN E1=: UUm%P3l"ckVV D/&2R/ a num3erN 3 num3erN 1/,-N 33 a ' $ a5aila$le here D/&2R/ 3 char(00'N 1/,-N 33 a and char t.2e $ i" a5aila$le here 33 n#m$er t.2e $ i" a5aila$le #"in- MMm.F$lockLL.$ /NDN ------ /NDN P,4S+, CO(TRO, STR%CT%RES )24S72 has a $ariet% "! c"ntr"l structures that all"6 %"u t" c"ntr"l the 3eha$i"ur "! the 3l"ck as it runs( These structures include c"nditi"nal statements and l""ps( -!-then-else &ase o &ase 6ith n" else o 2a3eled case o Searched case 113 Simple l""p =hile l""p G"r l""p ,"t" and 2a3els F3THE(3E,SE S.nta1: -! Uc"nditi"n0V then Se8uence "! statementsN /lsei! Uc"nditi"n0V then Se8uence "! statementsN XX /lse Se8uence "! statementsN /nd i!N E1: D/&2R/ dn" num3er(2'N 1/,-N select deptn" int" dn" !r"m dept 6here dname S I&&+#NT-N,IN if dn" S 00 then d3msP"utput(putPline(I2"cati"n is N/= H+RKI'N el"eif dn" S 20 then d3msP"utput(putPline(I2"cati"n is D22SI'N el"eif dn" S 30 then d3msP"utput(putPline(I2"cati"n is &A-&,+I'N el"e d3msP"utput(putPline(I2"cati"n is 1+ST+NI'N end ifN /NDN O#t2#t: 2"cati"n is N/= H+RK C&SE S.nta1: &ase test-variable =hen value1 then sequence of statements; =hen value2 then sequence of statements; . . 114 =hen valuen then sequence of statements; /lse sequence of statements; /nd caseN E1: D/&2R/ dno num3er(2'N 1/,-N select deptn" int" dno !r"m dept 6here dname S I&&+#NT-N,IN case dno 6hen :D then d3msP"utput(putPline(I2"cati"n is N/= H+RKI'N 6hen <D then d3msP"utput(putPline(I2"cati"n is D22SI'N 6hen =D then d3msP"utput(putPline(I2"cati"n is &A-&,+I'N el"e d3msP"utput(putPline(I2"cati"n is 1+ST+NI'N end caseN /NDN O#t2#t: 2"cati"n is N/= H+RK C&SE 9THO%T E,SE S.nta1: &ase test-variable =hen value-1 then sequence of statements; =hen value-2 then sequence of statements; XX =hen value-n then sequence of statements; 115 /nd caseN E1: D/&2R/ dn" num3er(2'N 1/,-N select de2tno int" dno !r"m dept 6here dname S I&&+#NT-N,IN case dno 6hen :D then d3msP"utput(putPline(I2"cati"n is N/= H+RKI'N 6hen <D then d3msP"utput(putPline(I2"cati"n is D22SI'N 6hen =D then d3msP"utput(putPline(I2"cati"n is &A-&,+I'N 6hen >D then d3msP"utput(putPline(I2"cati"n is 1+ST+NI'N end caseN /NDN O#t2#t: 2"cati"n is N/= H+RK ,&BE,E) C&SE S.nta1: UUla3elVV &ase test-$aria3le =hen $alue0 then se8uence "! statementsN =hen $alue2 then se8uence "! statementsN XX =hen $aluen then se8uence "! statementsN 116 /nd caseN E1: D/&2R/ dn" num3er(2'N 1/,-N select deptn" int" dn" !r"m dept 6here dname S I&&+#NT-N,IN UUm%PcaseVV case dn" 6hen 00 then d3msP"utput(putPline(I2"cati"n is N/= H+RKI'N 6hen 20 then d3msP"utput(putPline(I2"cati"n is D22SI'N 6hen 30 then d3msP"utput(putPline(I2"cati"n is &A-&,+I'N 6hen :0 then d3msP"utput(putPline(I2"cati"n is 1+ST+NI'N end case m.Fca"eI /NDN O#t2#t: 2"cati"n is N/= H+RK SE&RCHE) C&SE S.nta1: &ase =hen Ucondition-1V then sequence of statements; =hen Ucondition-2V then sequence of statements; XX =hen Ucondition-nV then sequence of statements; /nd caseN 117 E1: D/&2R/ dn" num3er(2'N 1/,-N select de2tno int" dno !r"m dept 6here dname S I&&+#NT-N,IN case dno 6hen dno V :D then d3msP"utput(putPline(I2"cati"n is N/= H+RKI'N 6hen dno V <D then d3msP"utput(putPline(I2"cati"n is D22SI'N 6hen dno V =D then d3msP"utput(putPline(I2"cati"n is &A-&,+I'N 6hen dno V >D then d3msP"utput(putPline(I2"cati"n is 1+ST+NI'N end caseN /NDN O#t2#t: 2"cati"n is N/= H+RK SMP,E ,OOP S.nta1: 2""p Sequence of statements; /9it 6hen UconditionVN /nd l""pN -n the s%nta9 e9it 6hen UconditionV is e8ui$alent t" -! UconditionV then /9itN 118 /nd i!N E1: D/&2R/ i num3er BS 0N 1/,-N loo2 d3msP"utput(putPline(Ii S I ^^ i'N i BS i C 0N e9it 6hen i V ;N end loo2I /NDN O#t2#t: i S 0 i S 2 i S 3 i S : i S ; 9H,E ,OOP S.nta1: =hile Uc"nditi"nV l""p Sequence of statements; /nd l""pN E1: D/&2R/ i num3er BS 0N 1/,-N 9hile i US ; loo2 119 d3msP"utput(putPline(Ii S I ^^ i'N i BS i C 0N end loo2I /NDN O#t2#t: i S 0 i S 2 i S 3 i S : i S ; FOR ,OOP S.nta1: G"r Uloop_counter_variableV in low_bound((i!_bound l""p Sequence of statements; /nd l""pN E1:: 1/,-N For i in 0((; loo2 d3msP"utput(putPline(Ii S I ^^ i'N end loo2N /NDN 120 O#t2#t: i S 0 i S 2 i S 3 i S : i S ; E1<: 1/,-N G"r i in re$erse 0((; l""p d3msP"utput(putPline(Ii S I ^^ i'N end l""pN /NDN O#t2#t: i S ; i S : i S 3 i S 2 i S 0 6OTO &() ,&BE,S S.nta1: ,"t" labelN =here label is a la3el de!ined in the )24S72 3l"ck( 2a3els are encl"sed in d"u3le angle 3rackets( =hen a g"t" statement is e$aluated, c"ntr"l immediatel% passes t" the statement identi!ied 3% the la3el( E1: 1/,-N For i in 0((; loo2 d3msP"utput(putPline(Ii S I ^^ i'N i! i S : then 121 g"t" e9itPl""pN end i!N end loo2N UUe9itPl""pVV NullN /NDN O#t2#t: i S 0 i S 2 i S 3 i S : Restricti"ns "n ,+T+ -t is illegal t" 3ranch int" an inner 3l"ck, l""p( t least "ne e9ecuta3le statement must !"ll"6( -t is illegal t" 3ranch int" an i! statement( -t is illegal t" 3ranch !r"m "ne i! statement t" an"ther i! statement( -t is illegal t" 3ranch !r"m e9cepti"n 3l"ck t" the current 3l"ck( 122 RES%,T: Thus the Stud% "! )24S72 3l"ck has 3een implemented 3% $ari"us c"ntr"l structure are $eri!ied and e9ecuted success!ull%( !r"te a #L/S$L bloc% to sat"s&' some cond"t"ons b' acce(t"ng "n(ut &rom the user) E1: (o: DA FF : FF : FF &M: T" implement the )24S72 3l"ck t" satis!% s"me c"nditi"ns 3% accepting input !r"m the user( &,6ORTHM: STEP :: Start the pr"gram( STEP <: &reate the ta3le 6ith its essential attri3utes( 123 STEP =: -nsert attri3ute $alues int" the ta3le( STEP >: &reate the )24S72 1l"ck 6ith necessar% 3l"cks( STEP ?: Declare the necessar% $aria3le in the declarati"n secti"n STEP @: 6rite the main pr"gram l"gics in the 3egin 3l"ck( STEP A: i! %"u 6ant t" access the ta3le use the S72 statement( STEP B: i! %"u 6ant t" s"l$e an% e9cepti"n, 6rite the e9cepti"n name 6ith =A/N stetment STEP C: /9ecute the )24S72 3l"ck( STEP :DB ,i$e the input $alues "r $alidate the in!"rmati"n !r"m the ta3les( STEP ::: St"p the pr"gram( +:: =rite )24S72 3l"ck 6hich 6ill calculate s"me "! t6" num3ers and displa% the "utput] D/&2R/ num3er(2'N 1 num3er(2'N & num3er(3'N 1/,-N BS 00N 1 BS 20N & BS C 1N D1MSP+#T)#T()#TP2-N/(&'N D1MSP+#T)#T()#TP2-N/( Lsum "! t6" num3ersM ^^ &'N /NDN 4 O#t2#t: 30 sum "! t6" num3ers 30 124 )24S72 pr"cedure success!ull% c"mpleted( +<: =rite a )24S72 3l"ck 6hich accepts empl"%ee num3er and increment is salar% 3% 0000] D/&2R/ num3er(:'N BS 5/mpn"N #pdate emp set sal S sal C 0000 6here /mpn" S N /NDN 4 +=: =rite a )24S72 3l"ck 6hich empn" and delete that r"6 !r"m the emp ta3le] D/&2R/ num3er(:'N 1/,-N BS 5/mpn"N Delete !r"m emp 6here /mpn" S N /NDN 4 +>: )24S72 !"r re$ersing the gi$en string &l-orithm: 0( ,et the input string( 2( Gind the length "! the string( 3( /9tract the characters "ne 3% "ne !r"m the end "! the string( :( &"ncatenate the e9tracted characters( ;( Displa% the c"ncatenated re$ersed string( 6( St"p the pr"gram( Pro-ram: declare 3 $archar2(00' BS I53IN c $archar2(00'N l num3er(2'N i num3er(2'N g num3er(2'N 125 d $archar2(00'N 3egin lBSlength(3'N gBSlN !"r i in 0((l l""p cBSsu3str(3,g,0'N g BS g - 0N d BS d ^^ cN end l""pN d3msP"utput(putPline(Ire$ised string isI'N d3msP"utput(putPline(d'N endN O%TP%T: /nter $alue !"r 3B ramu "ld 2B 3 $archar2(00' BS I53IN ne6 2B 3 $archar2(00' BS IramuIN re$ised string is umar )24S72 pr"cedure success!ull% c"mpleted( +?: P,4S+, !"r Gi3"nacci Series( &l-orithm: 0( ,et the n"("! terms N, in the !i3"nacci series t" 3e generated( 2( -! N is less than 2, then raise an e9cepti"n and displa% the message( 3( +ther6ise initialiFe the $alue "! as 0 and 1 as 0 and displa% them( :( Repeat the steps ;56 in N-3 times( ;( &BSC1 5 Displa% &( 6( BS151BS <( St"p the pr"gram( Pro-ram: declare a num3er(3'N3 num3er(3'Nc num3er(3'Nn num3er(3'BS5nN negati$e e9cepti"nN 3egin i! n U 2 then raise negati$eN end i!N 126 a BS 0N3 BS 0N d3msP"utput(putPline(I!i3"nacci series isI'N d3msP"utput(putPline(a'N d3msP"utput(putPline(3'N !"r i in 3 (( n l""p c BS a C 3N d3msP"utput(putPline(c'N a BS 3N 3 BS cN end l""pN e9cepti"n 6hen negati$e then d3msP"utput(putPline(In sh"uld 3e greater than 0I'N endN S+,L 4 /nter $alue !"r nB00 "ld ;B n num3er(3'BS5nN ne6 ;Bn num3er(3'BS00N Gi3"nacci 0 0 0 2 3 ; > 03 20 3: P,4S+, pr"cedure success!ull% c"mpleted +@: )r"gram t" check 6hether gi$en num3er is rmstr"ng "r n"t( &l-orithm: Step 0B Declare the $aria3le N, S, D and D#)( Step 2B St"re the $alue in $ar( N and $ar( D#)(( Step 3B check !"r the $alue "! N, 6hich is n"t e8ual t" 0( Step :B di$ide $alue st"red in N 3% 00 and st"re it $ar( D( (DSn_00'( Step ;B the reminder 6ill 3e multipl% 3 times and st"re it in .ar( S( Step 6B The c"e!!icient 6ill 3e calculated using G2++R !uncti"n( nd st"re it in $ar( N( Step <B repeat the Steps 3, :, ;, and 6 till l""p 6ill 3e terminated( Step >B &heck 6hether the st"red $alue and calculated $alues are same Step ?B i! 3"th the $alues are same, then displa% JThe gi$en num3er is rmstr"ngK Step 00B +ther6ise displa% Jit is n"t rmstr"ngK and terminate the l""p( 127 Declare N num3erN S num3erN D num3erN 1egin NBS5nN SBS0N =hile(nTS0' 2""p DSn_00N SBSsC(DQDQD'N NBS!l""r(n400'N /nd l""pN -! (D#)SS' then D1MSP"utput(putPline(Lnum3er is armstr"ngM'N /lse D1MSP"utput(putPline(Lnum3er is n"t armstr"ngM'N /nd i!N /ndN Te"t !alid )ata Set: /nter $alue "! n 0;3 O#t2#t: num3er is rmstr"ng +A: =rite a pr"gram t" generate all prime num3ers 3el"6 000( &MB t" generate all prime num3ers 3el"6 000( Declare - num3erN D num3erN & num3erN 1egin =hile(iUS000' 2""p &BS0N DBS0N =hile(@USi' 2""p -!(!l""r(i_@'S0' then &BS &C0N /nd i!N DBS@C0N /nd l""pN -!(cS2' then D3msP"utput(putPline(i'N /nd i!N /ndl""pN /ndN 128 !alid Te"t )ata O%TP%T: 2 3 ; < 00 ( ( ?? +B: =rite a pr"gram t" dem"nstrate _t%pe and _r"6t%pe attri3utes &MB t" dem"nstrate _t%pe and _r"6t%pe attri3utes Declare M%P/mpn" emp(empn"_t%peN M%P/name emp(ename_t%peN M%P/mpr"6 emp_r"6t%peN N" num3erN 1egin N"BS5n"N Select empn",ename int" m%Pempn",m%Pename !r"m emp 6here empn"Sn"N -!(S7l_r"6c"untS0' then D3msP"utput(putPline(Lempn" isM ^^ m%Pempn" ^^ Lename is L ^^ m%Pename'N /lse D3msP"utput(putPline( Lerr"rM'N /nd i!N Select Q int" m%Pempr"6 !r"m emp 6here empn"Sn"N -!(S7l_r"6c"untS0' then D3msP"utput(putPline(Lempn" isM ^^ m%Pempr"6(empn" ^^ Lename is L ^^ m%Pempr"6(ename'N /lse D3msP"utput(putPline( Lerr"rM'N /nd i!N /ndN 129 !alid Te"t )ata /nter the $alue !"r n"B <<>> O%TP%T empn" is <<>> ename is $ina% s( empn" is <<>> ename is $ina% s( RES%,T: Thus the )24S72 3l"ck t" satis!% s"me c"nditi"ns 3% accepting input !r"m the user has 3een $eri!ied and e9ecuted success!ull%( !r"te a #L/S$L bloc% that handles all t'(es o& e*ce(t"ons. E1: (o: DB FF : FF : FF &M: T" =rite a )24S72 3l"ck that handles all t%pes "! e9cepti"ns( &,6ORTHM: STEP:: Start the pr"gram( STEP<: &reate a ta3le 6ith s"me $alid data( STEP=: 6rite the )24S72 pr"gram that t" handle the e9cepti"n "n e9cepti"n 3l"ck STEP>: /9ecute the )24S72 pr"gram and gi$e the input $alues "r make the err"r "n the ta3le data( STEP?: Displa% the )24S72 pr"gram err"r message( STEP@: St"p the pr"gram( E7CEPTO(SB 130 -n )24S72, err"rs and 6arnings are called as e9cepti"ns( =hene$er a prede!ined err"r "ccurs in the pr"gram, )24S72 raises an e9cepti"n( G"r e9ample, i! %"u tr% t" di$ide a num3er 3% Fer" then )24S72 raises an e9cepti"n called O/R+PD-.-D/ and i! S/2/&T can n"t !ind a rec"rd then )24S72 raises e9cepti"n N+PDTPG+#ND( )24S72 has a c"llecti"n "! prede!ined e9cepti"ns( /ach e9cepti"n has a name( These e9cepti"ns are aut"maticall% raised 3% )24S72 6hene$er the c"rresp"nding err"r "ccurs( -n additi"n t" )24S72 prede!ined e9cepti"ns, user can als" create his "6n e9cepti"ns t" deal 6ith err"rs in the applicati"ns( The% are three t%pes "! /9cepti"ns( 0( +R&2/ )rede!ined /9cepti"n 2( +R&2/ N"n )rede!ined /9cepti"n 3( #S/R De!ined /9cepti"n SH(T&7 OF E7CEPTO( H&(),(6 =A/N e9cepti"n-0 Y"r e9cepti"n -2Z ((( TA/N statementsN Y=A/N e9cepti"n-3 Y"r e9cepti"n-:Z ((( TA/N statementsN Z ((( Y=A/N +TA/RS TA/N statementsN Z Q: The foowng exampe handes NO<DATA<FOUND excepton. decare . begn seect . excepton when no<8!t!<9oun8 then statements; end; O#t2#t: 131 Q: The foowng excepton handng part takes the same acton when ether NO<DATA<FOUND or TOO<MANY<ROWS exceptons occur. decare ... begn seect ... excepton when no_data_found o% too_many_rows then statements; end; O#t2#t: Q: The foowng snppet handes these two exceptons n dherent ways. decare ... begn seect ... excepton when no<8!t!<9oun8 then statements; when too<0!n*<%o/s then statements; end; O#t2#t: WHEN OTHERS s used to execute statements when an excepton other than what are mentoned n excepton hander has occurred. decare newccode varchar2(5) := nu; begn update courses set ccode = newccode where ccode = 'c'; excepton when 8u4<.!#<on<in8$+ then 132 dbms_output.put_ne('Dupcate course code'); /&$n ot&$%s then dbms_output.put_ne( sqerrm); end; O#t2#t: Predefined e1ce2tion" )24S72 has de!ined certain c"mm"n err"rs and gi$en names t" these err"rs, 6hich are called as prede!ined e9cepti"ns( /ach e9cepti"n has a c"rresp"nding +racle err"r c"de( The !"ll"6ing is the list "! prede!ined e9cepti"ns and the c"rresp"nding +racle err"r c"de( (OF)&T&FFO%()B 133 This /9cepti"n is Raised i! a S/2/&T -NT+ statement returns n" r"6s "r i! %"u re!erence an un- initialiFed r"6 in a )24S72 ta3le( E1B Declare 2Psal emp(sal_t%peN 1egin D1MSP+#T)#T()#TP2-N/( L=/2&+M/M 'N Select sal -NT+ 2Psal !r"m emp 6here empn" S 5empn"N D1MSP+#T)#T()#TP2-N/(2Psal'N D1MSP+#T)#T()#TP2-N/( LTANK H+#M 'N /E&/)T-+N 6hen (OF)&T&FFO%() then D1MSP+#T)#T()#TP2-N/( L-N.2-D /M)N+M'N /NDN 4 TOOFM&(HFRO9SB This /9cepti"n is Raised i! a S/2/&T -NT+ statement returns m"re than "ne r"6( E1B Declare 2Psal emp(sal_t%peN 1egin D1MSP+#T)#T()#TP2-N/( L=/2&+M/M 'N Select sal -NT+ 2Psal !r"m emp 6here deptn" S 30N D1MSP+#T)#T()#TP2-N/(2Psal'N D1MSP+#T)#T()#TP2-N/( LTANK H+#M 'N /E&/)T-+N 6hen T++PMNHPR+=S then D1MSP+#T)#T()#TP2-N/( LM+R/ TA/N +N/ R+= R/T#RN/DM'N /NDN 4 WEROF)!)EB Raised 6hen %"ur pr"gram attempts t" di$ide a num3er 3% Fer"( E1B Declare Num3erN 1egin BS ;40N /9cepti"n 134 6hen O/R+PD-.-D/ then D1MSP+#T)#T()#TP2-N/( LD+ N+T D-.-D/ 1H 0M 'N /NDN 4 (oteB This /9cepti"n is raised 6hen 6e tr% t" di$ided 3% Fer"( !&,%EFERRORB This /9cepti"n is raised 6hen there is miss match 6ith the $alue and data t%pe "! l"cal $aria3le "r siFe "! l"cal $aria3les( E1 0B Declare 2Psal emp(sal_t%peN 1egin D1MSP+#T)#T()#TP2-N/( L=/2&+M/M 'N Select ename -NT+ 2Psal !r"m emp 6here empn" S <;20N D1MSP+#T)#T()#TP2-N/(2Psal'N D1MSP+#T)#T()#TP2-N/( LTANK H+#M 'N /E&/)T-+N 6hen .2#/P/RR+R then D1MSP+#T)#T()#TP2-N/( Lplease check the l"cal $aria3lesM'N /NDN 4 E1 2B Declare num3er(3'N 1egin BS 023:N /9cepti"n 6hen .2#/P/RR+R then D1MSP+#T)#T()#TP2-N/( L)2/S/ &A/&K TA/ 2+&2 .R-12/SM 'N /NDN 4 )%PF!&,FO(F()E7B (duplicate $alue "n inde9' This /9cepti"n is raised 6hen 6e tr% t" insert a duplicate $alue in primar% ke% c"nstraint( 135 E1B 1egin D1MSP+#T)#T()#TP2-N/( L6elc"meM 'N -nsert int" student $alues(00:, LR#NM,60'N D1MSP+#T)#T()#TP2-N/( LThank %"uM 'N /9cepti"n 6hen D#)P.2P+NP-ND/E then D1MSP+#T)#T()#TP2-N/(L D" n"t insert duplicatesM 'N /NDN 4 The a3"$e pr"gram 6"rks "n an assumpti"n the ta3le student !"r i! ha$ing a primar% ke% SN+ c"lumn 6ith $alue 00:( 9HE( OTHERSB =hen "thers are a uni$ersal /9cepti"n angular this can catch all the /9cepti"ns( Declare 2Psal num3er(:'N num3erN 1egin D1MSP+#T)#T()#TP2-N/( L=elc"meM 'N Select sal -NT+ 2PS2 !r"m emp 6here deptn" S 5deptn"N D1MSP+#T)#T()#TP2-N/(LThe sal is X(M^^2Psal'N BS0040N D1MSP+#T)#T()#TP2-N/( LThank %"uM 'N /9cepti"n =A/N +TA/RS TA/N D1MSP+#T)#T()#TP2-N/( Lplease check the c"deM 'N /NDN 4 ERROR REPORT(6 F%(CTO(SB The% are t6" /rr"r Rep"rting !uncti"ns( 0( S72&+D/ 2( S72/RRM These err"r rep"rting !uncti"ns are used in 6hen "thers clause t" identi!ied the e9cepti"n 6hich is raised( 0( S+,CO)EB -t returns /RR+R&+D/ 2( S+,ERRMB -t returns /9cepti"n num3er and /9cepti"n message( (oteB !"r N+PDTPG+#ND /9cepti"n S72&+D/ 6ill return 000( Declare 2Psal num3er(:'N num3erN 136 1egin D1MSP+#T)#T()#TP2-N/( L=elc"meM 'N Select sal -NT+ 2PS2 !r"m emp 6here deptn" S 5deptn"N D1MSP+#T)#T()#TP2-N/(LThe sal is X(M^^2Psal'N BS0;40N D1MSP+#T)#T()#TP2-N/( LThank %"uM 'N /9cepti"n =A/N +TA/RS TA/N D1MSP+#T)#T()#TP2-N/( Lplease check the c"deM 'N D1MSP+#T)#T()#TP2-N/(S72&+D/'N D1MSP+#T)#T()#TP2-N/(S72/RRM'N /NDN 4 (ESTE) B,OC8B Declare num3er BS 00N 1egin D1MSP+#T)#T()#TP2-N/(LA/22+0M'N Declare 1 num3er BS 20N 1egin D1MSP+#T)#T()#TP2-N/(LA/22+2M'N D1MSP+#T)#T()#TP2-N/(1'N D1MSP+#T)#T()#TP2-N/('N /NDN D1MSP+#T)#T()#TP2-N/(LA/22+3M'N D1MSP+#T)#T()#TP2-N/(1'N --/RR+R /NDN 4 (oteB "uter 3l"ck $aria3les can 3e accessed in nested 3l"ck nested 3l"ck $aria3les can n"t 3e accessed in "uter 3l"ck( E7CEPTO( PROP&6&TO(B 1egin D1MSP+#T)#T()#TP2-N/(LA/22+0M'N 2PS2 /M)(S2_TH)/N 1egin D1MSP+#T)#T()#TP2-N/(LA/22+2M'N 137 Select sal -NT+ 2PS2 !r"m emp 6here empn" S 0000N D1MSP+#T)#T()#TP2-N/(LA/22+3M'N /NDN D1MSP+#T)#T()#TP2-N/(LA/22+:M'N /E&/)T-+N =A/N N+PDTPG+#ND TA/N D1MSP+#T)#T()#TP2-N/(LA/22+;M'N /NDN 4 OR&,E (O( PRE)EF(E) E7CEPTO(SB These /9cepti"ns 6ill ha$e "nl% /9cepti"n num3er( 1ut d"es n"t ha$e /9cepti"n name( Steps t" handle n"n prede!ined e9cepti"ns( S.nta1B Step0B Declare the /9cepti"n U/E&/)T-+NPNM/V /E&/)T-+NN Step2B ss"ciate the /9cepti"n )R,M /E&/)T-+NP-N-T(U/E&/)T-+NPNM/V,U/E&/)T-+N N+V'N Step3B &atch the /9cepti"n =A/N U/E&/)T-+NPNM/V TA/N ------------------ ------------------ ------------------ /NDN 4 +R -22?2 is an e9ample "! n"n prede!ined e9cepti"n( This e9cepti"n is raised 6hen 6e delete r"6 !r"m a parent ta3le( -! the c"rresp"nding $alue e9isting the child ta3le( Declare MHP/E0 /9cepti"nN --step0 )R,M /E&/)T-+NP-N-T(MHP/E0, -22?2'N --step2 1egin D1MSP+#T)#T()#TP2-N/(L=elc"meM'N Select !r"m student 6here en" S 002N /E&/)T-+N =A/N MHP/E0 TA/N --step3 D1MSP+#T)#T()#TP2-N/(Ld" n"t delete pargma ta3leM'N 138 /NDN 4 )ragma /9cepti"nPinit is a c"mpiler directi$e 6hich is used t" ass"ciated an /9cepti"n name t" the prede!ined num3er( %SER )EF(E) E7CEPTO(B
These /9cepti"ns are de!ined and c"ntr"lled 3% the user( These /9cepti"ns neither ha$e prede!ined name n"r ha$e prede!ined num3er( Steps t" handle user de!ined /9cepti"ns( Ste2:: )eclare the E1ce2tion declare out_of_stock exception; begin statements; end; Ste2<: Rai"ed the E1ce2tion if qty < 10 then raise out_of_stock; end if; Ste2=: Catch the E1ce2tion exception when out_of_stock then -- handle the exception (that is reraised in outer block !!! end; E1 Declare MHP/E0 /E&/)T-+NN --Step0 2PS2 /M)(S2_TH)/N 1egin D1MSP+#T)#T()#TP2-N/(L6elc"meM'N Select S2 -NT+ 2PS2 !r"m emp 6here empn" S 5empn"N -G 2PS2 V 2000 TA/N R-S/ MHP/E0N --Step2 /ND-GN D1MSP+#T)#T()#TP2-N/(LThe sal is X L^^2Psal'N 139 D1MSP+#T)#T()#TP2-N/(LThank %"uM'N /E&/)T-+N =A/N MHP/E0 TA/N --Step3 D1MSP+#T)#T()#TP2-N/(LSal is t6" highM'N /NDN 4 (oteB =hen "thers sh"uld 3e the last handler "! the e9cepti"n secti"n "ther 6ise 6e get a c"mpiler /RR+R( R&SEF&PP,C&TO(FERROR: R-S/P))2-&T-+NP/RR+R is a pr"cedure 6hich is used t" thr"6 "ne err"r num3er and err"r message t" the calling en$ir"nment( -t internall% per!"rmance r"lls 3ack( /RR+R num3er sh"uld 3e range "! -20000 t" -20???( /RR+R message sh"uld 3e displa%ed less then "r e8ual t" ;02 characters( Declare 2Psal emp(sal_TH)/N 1egin D1MSP+#T)#T()#TP2-N/(L=elc"meM'N -nsert -NT+ dept $alues (0>,MarunM,<0'N Select sal -NT+ 2Psal !r"m emp 6here empn" S <6?>N -G 2Psal V 2000 TA/N R-S/P))2-&T-+NP/RR+R(-200;0, LS2 -S T++ A-,AM'N /ND -GN D1MSP+#T)#T()#TP2-N/(LTA/ S2 -SXM^^2PS2'N /NDN 4 140 RES%,T: Thus the )24S72 3l"ck that handles all t%pes "! e9cepti"ns has 3een $eri!ied and e9ecuted success!ull%( Creat"on o& #rocedures) E1: (o: DC FF : FF : FF &M: T" 6rite a )24S72 3l"ck t" displa% the student name, marks 6h"se a$erage mark is a3"$e 60_( &,6ORTHM: STEP:: Start the pr"gram( STEP<: &reate a ta3le 6ith ta3le name studPe9am STEP=: -nsert the $alues int" the ta3le and &alculate t"tal and a$erage "! each student STEP>: /9ecute the pr"cedure !uncti"n the student 6h" get a3"$e 60_( STEP?: Displa% the t"tal and a$erage "! student STEP@: Terminate the applicati"n 141 SH(T&7 &R/T/ Y+R R/)2&/Z )R+&/D#R/ name Y(parameterY,parameter, (((Z'Z [-S^S\ Yl"cal declarati"nsZ 1/,-N e9ecuta3le statements Y/E&/)T-+N e9cepti"n handlersZ /ND YnameZN E7EC%TO(: S72V S/T S/R./R+#T)#T +N 0 PRO6R&M: PROCE)%RE %S(6 POSTO(&, P&R&METERS: SETT(6 SER!ERO%TP%T O(: S72V S/T S/R./R+#T)#T +N S72V &R/T/ +R R/)2&/ )R+&/D#R/ )R+&0 S 1/,-N D1MSP+#T)#T()#TP2-N/(IAell" !r"m pr"cedure(((I'N /NDN 4 O#t2#t: 142 )r"cedure created( S72V /E/&#T/ )R+&0 Aell" !r"m pr"cedure((( )24S72 pr"cedure success!ull% c"mpleted( 0 PRO6R&M: +: PROCE)%RE %S(6 (OT&TO(&, P&R&METERS: S72V &R/T/ +R R/)2&/ )R+&/D#R/ )R+&2(N0 -N N#M1/R,N2 -N N#M1/R,T+T +#T N#M1/R' -S 1/,-N T+T BS N0 C N2N /NDN 4 O#t2#t: )r"cedure created( S72V .R-12/ T N#M1/R S72V /E/& )R+&2(33,66,BT' )24S72 pr"cedure success!ull% c"mpleted( S72V )R-NT T T ---------- ?? 143 PROCE)%RE FOR 6C) (%MBERS 0 PRO6R&M: S72V create "r replace pr"cedure pr" is a num3er(3'N 3 num3er(3'N c num3er(3'N d num3er(3'N 3egin aBS5aN 3BS53N i!(aV3' then cBSm"d(a,3'N i!(cS0' then d3msP"utput(putPline(I,&D isI'N d3msP"utput(putPline(3'N else d3msP"utput(putPline(I,&D isI'N d3msP"utput(putPline(c'N end i!N else dBSm"d(3,a'N i!(dS0' then d3msP"utput(putPline(I,&D isI'N d3msP"utput(putPline(a'N else d3msP"utput(putPline(I,&D isI'N d3msP"utput(putPline(d'N end i!N end i!N 144 endN 4 O#t 2#t: /nter $alue !"r aB > "ld >B aBS5aN ne6 >B aBS>N /nter $alue !"r 3B 06 "ld ?B 3BS53N ne6 ?B 3BS06N )r"cedure created( S72V set ser$er"utput "nN S72V e9ecute pr"N ,&D is > RES%,T: 145 Thus the implementati"n "! )24S72 pr"cedure has 3een $eri!ied and e9ecuted success!ull%( C+,AT-.N ./ DATABAS, T+-00,+S AND /UNCT-.NS :D.: m2lementation of Tri--er" and it" &22lication E1: (o: :D FF : FF : FF &M: T" the -mplementati"n "! Triggers !"r the purp"se "! m"nit"r the data3ase "3@ect(ta3le((etc' !"r an% m"di!icati"n 3% the 8uer% user and4"r the pplicati"n pr"gram( &,6ORTHM: 0( Start the pr"gram( 2( &reate the ta3le 6ith its essential attri3utes( 3( -nsert attri3ute $alues int" the ta3le( :( &reate the trigger !"r a particular ta3le ;( Speci!% 6hen the trigger is t" 3e !ired - 3e!"re "r a!ter 6( Speci!% DM2 statement that in$"kes the trigger - #)DT/, D/2/T/, "r -NS/RT <( Speci!% the t%pe "! triger 6hether r"6-le$el trigger "r n"t >( &"nditi"n t" !ilter r"6s( ?( )24S72 3l"ck that is t" 3e e9ecuted 6hen trigger is !ired( 00( M"di!% the speci!ied ta3le t" !ire the trigger( 00( Displa% the trigger message !"r the particular kind "! m"di!icati"n 02( St"p the pr"gram( 146 )&T&B&SE TR66ERS Triggers are similar t" pr"cedures "r !uncti"ns in that the% are named )24S72 3l"cks 6ith declarati$e, e9ecuta3le, and e9cepti"n handling secti"ns( trigger is e9ecuted implicitl% 6hene$er the triggering e$ent happens( The act "! e9ecuting a trigger is kn"6n as !iring the trigger( %SE OF TR66ERS Maintaining c"mple9 integrit% c"nstraints n"t p"ssi3le thr"ugh declarati$e c"nstraints ena3le at ta3le creati"n( uditing in!"rmati"n in a ta3le 3% rec"rding the changes made and 6h" made them( ut"maticall% signaling "ther pr"grams that acti"n needs t" take place 6hen chages are made t" a ta3le( )er!"rm $alidati"n "n changes 3eing made t" ta3les( ut"mate maintenance "! the data3ase( RESTRCTO(S O( TR66ERES 2ike packages, triggers must 3e st"red as stand-al"ne "3@ects in the data3ase and cann"t 3e l"cal t" a 3l"ck "r package( trigger d"es n"t accept arguments( THPES OF TR66ERS DM2 Triggers -nstead "! Triggers DD2 Triggers S%stem Triggers Suspend Triggers C&TE6ORES Timing -- 1e!"re "r !ter 2e$el -- R"6 "r Statement 147 R"6 le$el trigger !ires "nce !"r each r"6 a!!ected 3% the triggering statement( R"6 le$el trigger is identi!ied 3% the G+R /&A R+= clause( Statement le$el trigger !ires "nce either 3e!"re "r a!ter the statement( TR66ER SH(T&7 &R/T/ Y+R R/)2&/Z TR-,,/R trigername [1/G+R/ ^ GT/R\ [D/2/T/ ^ -NS/RT ^ #)DT/ Y+G c"lumnsZ\ Y+R [D/2/T/ ^ -NS/RT ^#)DT/ Y+G c"lumnsZ\Z((( +N ta3le YG+R /&A R+= Y=A/N c"nditi"nZZ YR/G/R/N&-N, Y+2D S "ldZ YN/= S ne6ZZ )24S72 3l"ck )M, TR66ERS DM2 trigger is !ired "n an -NS/RT, #)DT/, "r D/2/T/ "perati"n "n a data3ase ta3le( -t can 3e !ired either 3e!"re "r a!ter the statement e9ecutes, and can 3e !ired "nce per a!!ected r"6, "r "nce per statement( The c"m3inati"n "! these !act"rs determines the t%pes "! the triggers( These are a t"tal "! 02 p"ssi3le t%pes (3 statements Q 2 timing Q 2 le$els'( OR)ER OF )M, TR66ER FR(6 1e!"re statement le$el 1e!"re r"6 le$el !ter r"6 le$el !ter statement le$el E1: Supp"se 6e ha$e a !"ll6ing ta3le( S72V select Q !r"m studentN N+ NM/ MRKS ----- ---------- ------------ 0 a 000 2 3 200 148 3 c 300 : d :00 ls" 6e ha$e triggeringP!iringP"rder ta3le 6ith !iringP"rder as the !ield( E1: &R/T/ +R R/)2&/ TR-,,/R TR-,,/R0 3e!"re insert "n student 1/,-N insert int" triggerP!iringP"rder $alues(I1e!"re Statement 2e$elI'N /ND TR-,,/R0N E1: &R/T/ +R R/)2&/ TR-,,/R TR-,,/R2 3e!"re insert "n student !"r each r"6 1/,-N insert int" triggerP!iringP"rder $alues(I1e!"re R"6 2e$elI'N /ND TR-,,/R2N E1: &R/T/ +R R/)2&/ TR-,,/R TR-,,/R3 a!ter insert "n student 1/,-N insert int" triggerP!iringP"rder $alues(I!ter Statement 2e$elI'N /ND TR-,,/R3N E1: &R/T/ +R R/)2&/ TR-,,/R TR-,,/R: a!ter insert "n student !"r each r"6 1/,-N insert int" triggerP!iringP"rder $alues(I!ter R"6 2e$elI'N /ND TR-,,/R:N O#t2#t: S72V select Q !r"m triggerP!iringP"rderN n" r"6s selected S72V insert int" student $alues(;,IeI,;00'N 149 0 r"6 created( S72V select Q !r"m triggerP!iringP"rderN G-R-N,P+RD/R -------------------------------------------------- 1e!"re Statement 2e$el 1e!"re R"6 2e$el !ter R"6 2e$el !ter Statement 2e$el S72V select Q !r"m studentN N+ NM/ MRKS ----- ------------ -------------- 0 a 000 2 3 200 3 c 300 : d :00 ; e ;00 E1: Supp"se 6e ha$e a ta3le called marks 6ith !ields n", "ldPmarks, ne6Pmarks( &R/T/ +R R/)2&/ TR-,,/R +2DPN/= 3e!"re insert "r update "r delete "n student !"r each r"6 1/,-N insert int" marks $alues(B"ld(n",B"ld(marks,Bne6(marks'N /ND +2DPN/=N O#t2#t: S72V select Q !r"m studentN N+ NM/ MRKS ----- ------- - --------- 0 a 000 2 3 200 3 c 300 : d :00 ; e ;00 S72V select Q !r"m marksN n" r"6s selected 150 S72V insert int" student $alues(6,I!I,600'N 0 r"6 created( S72V select Q !r"m studentN N+ NM/ MRKS ----- ----------- -------------- 0 a 000 2 3 200 3 c 300 : d :00 ; e ;00 6 ! 600 S72V select Q !r"m marksN N+ +2DPMRKS N/=PMRKS ---- ------------------- ------------------- 600 S72V update student set marksS;;; 6here n"S;N 0 r"6 updated( S72V select Q !r"m studentN N+ NM/ MRKS ----- ------- ---------- 0 a 000 2 3 200 3 c 300 : d :00 ; e ;;; 6 ! 600 S72V select Q !r"m marksN N+ +2DPMRKS N/=PMRKS ------ ---------------- --------------- 600 ; ;00 ;;; S72V delete student 6here n" S 2N 0 r"6 deleted( S72V select Q !r"m studentN N+ NM/ MRKS ------ -------------- ------------ 0 a 000 3 c 300 : d :00 ; e ;;; 6 ! 600 S72V select Q !r"m marksN N+ +2DPMRKS N/=PMRKS ----- -------------- ---------------- 600 151 ; ;00 ;;; 2 200 REFERE(C(6 C,&%SE -! desired, %"u can use the R/G/R/N&-N, clause t" speci!% a di!!erent name !"r B"ld ane Bne6( This clause is !"und a!ter the triggering e$ent, 3e!"re the =A/N clause( S.nta1: R/G/R/N&-N, Y"ld as "ldPnameZ Yne6 as ne6PnameZ E1: &R/T/ +R R/)2&/ TR-,,/R R/G/R/N&/PTR-,,/R 3e!"re insert "r update "r delete "n student re!erencing "ld as "ldPstudent ne6 as ne6Pstudent !"r each r"6 1/,-N insert int" marks $alues(B"ldPstudent(n",B"ldPstudent(marks,Bne6Pstudent(marks'N /ND R/G/R/N&/PTR-,,/RN 9HE( C,&%SE =A/N clause is $alid !"r r"6-le$el triggers "nl%( -! present, the trigger 3"d% 6ill 3e e9ecuted "nl% !"r th"se r"6s that meet the c"nditi"n speci!ied 3% the =A/N clause( S.nta1: =A/N tri!!er_conditionN =here tri!!er_condition is a 1""lean e9pressi"n( -t 6ill 3e e$aluated !"r each r"6( The "new and "old rec"rds can 3e re!erenced inside tri!!er_condition as 6ell, 3ut like R/G/R/N&-N,, the c"l"n is n"t used there( The c"l"n is "nl% $alid in the trigger 3"d%( E1: &R/T/ +R R/)2&/ TR-,,/R =A/NPTR-,,/R 3e!"re insert "r update "r delete "n student re!erencing "ld as "ldPstudent ne6 as ne6Pstudent !"r each r"6 6hen (ne6Pstudent(marks V ;00' 1/,-N insert int" marks $alues(B"ldPstudent(n",B"ldPstudent(marks,Bne6Pstudent(marks'N /ND =A/NPTR-,,/RN 152 TR66ER PRE)C&TES There are three 1""lean !uncti"ns that %"u can use t" determine 6hat the "perati"n is( The predicates are -NS/RT-N, #)DT-N, D/2/T-N, E1: &R/T/ +R R/)2&/ TR-,,/R )R/D-&T/PTR-,,/R 3e!"re insert "r update "r delete "n student 1/,-N i! inserting then insert int" predicates $alues(I-I'N elsi! updating then insert int" predicates $alues(I#I'N elsi! deleting then insert int" predicates $alues(IDI'N end i!N /ND )R/D-&T/PTR-,,/RN O#t2#t: S72V delete student 6here n"S0N 0 r"6 deleted( S72V select Q !r"m predicatesN MS, --------------- D S72V insert int" student $alues(<,IgI,<00'N 0 r"6 created( S72V select Q !r"m predicatesN MS, --------------- D - 153 S72V update student set marks S <<< 6here n"S<N 0 r"6 updated( S72V select Q !r"m predicatesN MS, --------------- D - # (STE&)3OF TR66ERS -nstead-"! triggers !ire instead "! a DM2 "perati"n( ls", instead-"! triggers can 3e de!ined "nl% "n $ie6s( -nstead-"! triggers are used in t6" casesB T" all"6 a $ie6 that 6"uld "ther6ise n"t 3e m"di!ia3le t" 3e m"di!ied( T" m"di!% the c"lumns "! a nested ta3le c"lumn in a $ie6( RES%,T: Thus the -mplementati"n "! Triggers and its applicati"ns t" m"nit"r the m"di!icati"n in data3ase has 3een $eri!ied and e9ecuted success!ull%( :D.< MP,EME(T&TO( OF F%(CTO(S &() TS &PP,C&TO( 154 E1: (o: :D.< FF : FF : FF &M: T" 6rite the )24S72 3l"ck !"r the implementati"n "! !uncti"ns and its applicati"n( &,6ORTHM: STEP :: Start the pr"gram( STEP <: &reate the ta3le 6ith its essential attri3utes( STEP =: -nsert attri3ute $alues int" the ta3le( STEP >: &reate the !uncti"n 6ith necessar% arguments and return data t%pes( STEP ?: create the )24S72 3l"ck t" call 4 use the !uncti"n( STEP @: /9ecute the )24S72 pr"gram( STEP A: ,i$e the input $alues STEP B: /9tract4pr"cess the in!"rmati"n !r"m the !uncti"n( STEP C: St"p the pr"gram( STORE) F%(CTO( 155 !uncti"n is similar t" pr"cedure, e9cept that it returns a $alue( The calling pr"gram sh"uld use the $alue returned 3% the !uncti"n( CRE&TE F%(CTO( The create f#nction c"mmand is used t" create a st"red !uncti"n( SYNTA: &R/T/ Y+R R/)2&/Z G#N&T-+N name Y(parameterY,parameter, (((Z'Z RET%R( datat.2e [-S ^ S\ Yl"cal declarati"nsZ 1/,-N e9ecuta3le statements RET%R( 5al#eN Y/E&/)T-+N e9cepti"n handlersZ /ND YnameZN (ote: OR REP,&CE is used t" create a !uncti"n e$en th"ugh a !uncti"n 6ith the same name alread% e9ists RET%R( datat.2e speci!ies the t%pe "! data t" 3e returned 3% the !uncti"n( RET%R( statement in the e9ecuta3le part returns the $alue( The $alue must 3e "! the same t%pe as the return t%pe speci!ied using R/T#RN "pti"n in the header( #ser-de!ined )24S72 !uncti"ns can 3e used in S72 in the same manner as the standard !uncti"ns such as R+#ND and S#1STR + :: T" 6rite a )24S72 3l"ck t" implementati"n "! !act"rial using !uncti"n 0 PRO6R&M: 156 S72Vcreate !uncti"n !n!act(n num3er' return num3er is 3 num3erN 3egin 3BS0N !"r i in 0((n l""p 3BS3QiN end l""pN return 3N endN 4 S72VDeclare n num3erBS5nN % num3erN 3egin d3msP"utput(putPline(%'N endN 4 O#t2#t: Guncti"n created( /nter $alue !"r nB ; old <: n num3erBS5nN new <: n num3erBS;N 020 )24S72 pr"cedure success!ull% c"mpleted( +<:create a !uncti"n 6hich c"unt t"tal n"("! empl"%ees ha$ing salar% less than 6000( 4Pf#nction $od.P4 &reate "r replace !uncti"n c"untPemp(esal num3er'return num3er as &urs"r $inPcur as Select empn",sal !r"m empN 157 En" emp(empn"_t%peN Esal emp(sal_t%peN & num3erN 1egin +pen $inPcurN &BS0N l""p !etch $inPcur int" 9n",9salN i!(9salUesal' then cBScC0N end i!N e9it 6hen $inPcur_n"t!"undN end l""pN cl"se $inPcurN return cN endN 4 Guncti"n created( 4Pf#nction "2ecificationP4 Declare Ne num3erN Esal num3erN 1egin NeBSc"untPemp(9sal'N D3msP"utput(putPline(9sal'N D3maP"utput(putPline(Lthere are L^^ne^^Nempl"%eesM'N /ndN 4 O%TP%T There are > empl"%ees( +<: T" 6rite a )24S72 !uncti"n t" search an address !r"m the gi$en data3ase 0 PRO6R&M S72V create ta3le ph"ne3""k (ph"nePn" num3er (6' primar% ke%, username $archar2(30', d""rn" $archar2(00', 158 street $archar2(30', place $archar2(30', pinc"de char(6''N ta3le created( S72V insert int" ph"ne3""k $alues(20302,I$i@a%I,I0204;DI,I3harathi streetI,IN,+c"l"n%I,I62?002I'N 0 r"6 created( S72V insert int" ph"ne3""k $alues(2?:6<,I$asanthI,I3?D:I,IRK 3ha$anI,Isarakkal $ilaiI,I62?002I'N 0 r"6 created( S72V select Q !r"m ph"ne3""kN )A+N/PN+ #S/RNM/ D++RN+ STR//T )2&/ )-N&+D/ --------------- ---------------- ------------- ----------- ---------- -------------- 20302 $i@a% 0204;D 3harathi street N,+ c"l"n% 62?002 2?:6< $asanth 3?D: RK 3ha$an sarakkal $ilai 62?002 S72V create "r replace !uncti"n !indddress(ph"ne in num3er' return $archar2 as address $archar2(000'N 3egin select username^^I,I^^d""rn" ^^I,I^^street ^^I,I^^place^^I,I^^pinc"de int" address !r"m ph"ne3""k 6here ph"nePn"Sph"neN return addressN e9cepti"n 6hen n"PdataP!"und then return Iaddress n"t !"undIN endN 4 Guncti"n created( declare address $archar2(000'N 3egin addressBS!indaddress(20302'N d3msP"utput(putPline(address'N 159 endN 4 O%TP%T :: .i@a%,0204;D,3harathi street,N,+ c"l"n%,62?002 )24S72 pr"cedure success!ull% c"mpleted( declare address $archar2(000'N 3egin addressBS!indaddress(23;;6'N d3msP"utput(putPline(address'N endN 4 O%TP%T<: ddress n"t !"und )24S72 pr"cedure success!ull% c"mpleted( Re"#ltB Thus the implementati"n "! !uncti"ns and its applicati"ns has 3een e9ecuted success!ull%( SU##L,M,NT - A DBMS LAB 1-1A $U,ST-.NS 0( =hat is data3ase] 160 data3ase is a l"gicall% c"herent c"llecti"n "! data 6ith s"me inherent meaning, representing s"me aspect "! real 6"rld and 6hich is designed, 3uilt and p"pulated 6ith data !"r a speci!ic purp"se( 2( =hat is D1MS] -t is a c"llecti"n "! pr"grams that ena3les user t" create and maintain a data3ase( -n "ther 6"rds it is general-purp"se s"!t6are that pr"$ides the users 6ith the pr"cesses "! de!ining, c"nstructing and manipulating the data3ase !"r $ari"us applicati"ns( 3( =hat is a Data3ase s%stem] The data3ase and D1MS s"!t6are t"gether is called as Data3ase s%stem( :( =hat are the ad$antages "! D1MS] 0( Redundanc% is c"ntr"lled( 2( #nauth"rised access is restricted( 3( )r"$iding multiple user inter!aces( :( /n!"rcing integrit% c"nstraints( ;( )r"$iding 3ackup and rec"$er%( ;( =hat is the disad$antage in Gile )r"cessing S%stem] 0( Data redundanc% and inc"nsistenc%( 2( Di!!icult in accessing data( 3( Data is"lati"n( :( Data integrit%( ;( &"ncurrent access is n"t p"ssi3le( 6( Securit% )r"3lems( 6( Descri3e the three le$els "! data a3stracti"n] The are hree le$els "! a3stracti"nB 0( )h%sical le$elB The l"6est le$el "! a3stracti"n descri3es h"6 data are st"red( 161 2( 2"gical le$elB The ne9t higher le$el "! a3stracti"n, descri3es 6hat data are st"red in data3ase and 6hat relati"nship am"ng th"se data( 3( .ie6 le$elB The highest le$el "! a3stracti"n descri3es "nl% part "! entire data3ase( <( De!ine the Rintegrit% rulesR] There are t6" -ntegrit% rules( 0( /ntit% -ntegrit%B States that R)rimar% ke% cann"t ha$e N#22 $alueR 2( Re!erential -ntegrit%B States that RG"reign Ke% can 3e either a N#22 $alue "r sh"uld 3e )rimar% Ke% $alue "! "ther relati"n( >( =hat is e9tensi"n and intensi"n] 0( /9tensi"nB -t is the num3er "! tuples present in a ta3le at an% instance( This is time dependent( 2( -ntensi"nB -t is a c"nstant $alue that gi$es the name, structure "! ta3le and the c"nstraints laid "n it( ?( =hat is S%stem R] =hat are its t6" ma@"r su3s%stems] S%stem R 6as designed and de$el"ped "$er a peri"d "! 0?<:-<? at -1M San D"se Research &enter( -t is a pr"t"t%pe and its purp"se 6as t" dem"nstrate that it is p"ssi3le t" 3uild a Relati"nal S%stem that can 3e used in a real li!e en$ir"nment t" s"l$e real li!e pr"3lems, 6ith per!"rmance at least c"mpara3le t" that "! e9isting s%stem( -ts t6" su3s%stems are 0( Research St"rage 2( S%stem Relati"nal Data S%stem( 00( A"6 is the data structure "! S%stem R di!!erent !r"m the relati"nal structure] #nlike Relati"nal s%stems in S%stem R 0( D"mains are n"t supp"rted 2( /n!"rcement "! candidate ke% uni8ueness is "pti"nal 162 3( /n!"rcement "! entit% integrit% is "pti"nal :( Re!erential integrit% is n"t en!"rced 00( =hat is Data -ndependence] Data independence means that Rthe applicati"n is independent "! the st"rage structure and access strateg% "! dataR( -n "ther 6"rds, The a3ilit% t" m"di!% the schema de!initi"n in "ne le$el sh"uld n"t a!!ect the schema de!initi"n in the ne9t higher le$el( T6" t%pes "! Data -ndependenceB 0( )h%sical Data -ndependenceB M"di!icati"n in ph%sical le$el sh"uld n"t a!!ect the l"gical le$el( 2( 2"gical Data -ndependenceB M"di!icati"n in l"gical le$el sh"uld a!!ect the $ie6 le$el( N+T/B 2"gical Data -ndependence is m"re di!!icult t" achie$e 02( =hat is a $ie6] A"6 it is related t" data independence] $ie6 ma% 3e th"ught "! as a $irtual ta3le, that is, a ta3le that d"es n"t reall% e9ist in its "6n right 3ut is instead deri$ed !r"m "ne "r m"re underl%ing 3ase ta3le( -n "ther 6"rds, there is n" st"red !ile that direct represents the $ie6 instead a de!initi"n "! $ie6 is st"red in data dicti"nar%( ,r"6th and restructuring "! 3ase ta3les is n"t re!lected in $ie6s( Thus the $ie6 can insulate users !r"m the e!!ects "! restructuring and gr"6th in the data3ase( Aence acc"unts !"r l"gical data independence( 03( =hat is Data M"del] c"llecti"n "! c"nceptual t""ls !"r descri3ing data, data relati"nships data semantics and c"nstraints( 0:( =hat is /-R m"del] This data m"del is 3ased "n real 6"rld that c"nsists "! 3asic "3@ects called entities and "! relati"nship am"ng these "3@ects( /ntities are descri3ed in a data3ase 3% a set "! attri3utes( 0;( =hat is +3@ect +riented m"del] 163 This m"del is 3ased "n c"llecti"n "! "3@ects( n "3@ect c"ntains $alues st"red in instance $aria3les 6ith in the "3@ect( n "3@ect als" c"ntains 3"dies "! c"de that "perate "n the "3@ect( These 3"dies "! c"de are called meth"ds( +3@ects that c"ntain same t%pes "! $alues and the same meth"ds are gr"uped t"gether int" classes( 06( =hat is an /ntit%] -t is a IthingI in the real 6"rld 6ith an independent e9istence( 0<( =hat is an /ntit% t%pe] -t is a c"llecti"n (set' "! entities that ha$e same attri3utes( 0>( =hat is an /ntit% set] -t is a c"llecti"n "! all entities "! particular entit% t%pe in the data3ase( 0?( =hat is an /9tensi"n "! entit% t%pe] The c"llecti"ns "! entities "! a particular entit% t%pe are gr"uped t"gether int" an entit% set( 20( =hat is =eak /ntit% set] n entit% set ma% n"t ha$e su!!icient attri3utes t" !"rm a primar% ke%, and its primar% ke% c"mpr"mises "! its partial ke% and primar% ke% "! its parent entit%, then it is said t" 3e =eak /ntit% set( 20( =hat is an attri3ute] -t is a particular pr"pert%, 6hich descri3es the entit%( 22( =hat is a Relati"n Schema and a Relati"n] relati"n Schema den"ted 3% R(0, 2, (((, n' is made up "! the relati"n name R and the list "! attri3utes i that it c"ntains( relati"n is de!ined as a set "! tuples( 2et r 3e the relati"n 6hich c"ntains set tuples (t0, t2, t3, (((, tn'( /ach tuple is an "rdered list "! n-$alues tS($0,$2, (((, $n'( 23( =hat is degree "! a Relati"n] -t is the num3er "! attri3ute "! its relati"n schema( 164 2:( =hat is Relati"nship] -t is an ass"ciati"n am"ng t6" "r m"re entities( 2;( =hat is Relati"nship set] The c"llecti"n ("r set' "! similar relati"nships( 26( =hat is Relati"nship t%pe] Relati"nship t%pe de!ines a set "! ass"ciati"ns "r a relati"nship set am"ng a gi$en set "! entit% t%pes( 2<( =hat is degree "! Relati"nship t%pe] -t is the num3er "! entit% t%pe participating( 2>( =hat is DD2 (Data De!initi"n 2anguage'] data 3ase schema is speci!ies 3% a set "! de!initi"ns e9pressed 3% a special language called DD2( 2?( =hat is .D2 (.ie6 De!initi"n 2anguage'] -t speci!ies user $ie6s and their mappings t" the c"nceptual schema( 30( =hat is SD2 (St"rage De!initi"n 2anguage'] This language is t" speci!% the internal schema( This language ma% speci!% the mapping 3et6een t6" schemas( 30( =hat is Data St"rage - De!initi"n 2anguage] The st"rage structures and access meth"ds used 3% data3ase s%stem are speci!ied 3% a set "! de!initi"n in a special t%pe "! DD2 called data st"rage-de!initi"n language( 32( =hat is DM2 (Data Manipulati"n 2anguage'] This language that ena3le user t" access "r manipulate data as "rganised 3% appr"priate data m"del( 165 0( )r"cedural DM2 "r 2"6 le$elB DM2 re8uires a user t" speci!% 6hat data are needed and h"6 t" get th"se data( 2( N"n-)r"cedural DM2 "r Aigh le$elB DM2 re8uires a user t" speci!% 6hat data are needed 6ith"ut speci!%ing h"6 t" get th"se data( 33( =hat is DM2 &"mpiler] -t translates DM2 statements in a 8uer% language int" l"6-le$el instructi"n that the 8uer% e$aluati"n engine can understand( 3:( =hat is 7uer% e$aluati"n engine] -t e9ecutes l"6-le$el instructi"n generated 3% c"mpiler( 3;( =hat is DD2 -nterpreter] -t interprets DD2 statements and rec"rd them in ta3les c"ntaining metadata( 36( =hat is Rec"rd-at-a-time] The 2"6 le$el "r )r"cedural DM2 can speci!% and retrie$e each rec"rd !r"m a set "! rec"rds( This retrie$e "! a rec"rd is said t" 3e Rec"rd-at-a-time( 3<( =hat is Set-at-a-time "r Set-"riented] The Aigh le$el "r N"n-pr"cedural DM2 can speci!% and retrie$e man% rec"rds in a single DM2 statement( This retrie$e "! a rec"rd is said t" 3e Set-at-a-time "r Set-"riented( 3>( =hat is Relati"nal lge3ra] -t is pr"cedural 8uer% language( -t c"nsists "! a set "! "perati"ns that take "ne "r t6" relati"ns as input and pr"duce a ne6 relati"n( 3?( =hat is Relati"nal &alculus] -t is an applied predicate calculus speci!icall% tail"red !"r relati"nal data3ases pr"p"sed 3% /(G( &"dd( 166 /(g( "! languages 3ased "n it are DS2 2)A, 7#/2( :0( A"6 d"es Tuple-"riented relati"nal calculus di!!er !r"m d"main-"riented relati"nal calculus] 0( The tuple-"riented calculus uses a tuple $aria3les i(e(, $aria3le 6h"se "nl% permitted $alues are tuples "! that relati"n( /(g( 7#/2 2( The d"main-"riented calculus has d"main $aria3les i(e(, $aria3les that range "$er the underl%ing d"mains instead "! "$er relati"n( /(g( -22, D/D#&/( :0( =hat is n"rmaliFati"n] -t is a pr"cess "! anal%sing the gi$en relati"n schemas 3ased "n their Guncti"nal Dependencies (GDs' and primar% ke% t" achie$e the pr"perties (0'(MinimiFing redundanc%, (2'( MinimiFing inserti"n, deleti"n and update an"malies( :2( =hat is Guncti"nal Dependenc%] Guncti"nal dependenc% is den"ted 3% E H 3et6een t6" sets "! attri3utes E and H that are su3sets "! R speci!ies a c"nstraint "n the p"ssi3le tuple that can !"rm a relati"n state r "! R( The c"nstraint is !"r an% t6" tuples t0 and t2 in r i! t0YEZ S t2YEZ then the% ha$e t0YHZ S t2YHZ( This means the $alue "! E c"mp"nent "! a tuple uni8uel% determines the $alue "! c"mp"nent H( :3( =hat is 2"ssless @"in pr"pert%] -t guarantees that the spuri"us tuple generati"n d"es n"t "ccur 6ith respect t" relati"n schemas a!ter dec"mp"siti"n( ::( =hat is 0 NG (N"rmal G"rm'] The d"main "! attri3ute must include "nl% at"mic (simple, indi$isi3le' $alues( :;( =hat is Gull% Guncti"nal dependenc%] -t is 3ased "n c"ncept "! !ull !uncti"nal dependenc%( !uncti"nal dependenc% E H is !ull !uncti"nal dependenc% i! rem"$al "! an% attri3ute !r"m E means that the dependenc% d"es n"t h"ld an% m"re( :6( =hat is 2NG] 167 relati"n schema R is in 2NG i! it is in 0NG and e$er% n"n-prime attri3ute in R is !ull% !uncti"nall% dependent "n primar% ke%( :<( =hat is 3NG] relati"n schema R is in 3NG i! it is in 2NG and !"r e$er% GD E either "! the !"ll"6ing is true 0( E is a Super-ke% "! R( 2( is a prime attri3ute "! R( -n "ther 6"rds, i! e$er% n"n prime attri3ute is n"n-transiti$el% dependent "n primar% ke%( :>( =hat is 1&NG (1"%ce-&"dd N"rmal G"rm'] relati"n schema R is in 1&NG i! it is in 3NG and satis!ies an additi"nal c"nstraint that !"r e$er% GD E , E must 3e a candidate ke%( :?( =hat is :NG] relati"n schema R is said t" 3e in :NG i! !"r e$er% Multi$alued dependenc% E H that h"lds "$er R, "ne "! !"ll"6ing is true( 0(' E is su3set "r e8ual t" ("r' EH S R( 2(' E is a super ke%( ;0( =hat is ;NG] Relati"n schema R is said t" 3e ;NG i! !"r e$er% @"in dependenc% [R0, R2, (((, Rn\ that h"lds R, "ne the !"ll"6ing is true 0(' Ri S R !"r s"me i( 2(' The @"in dependenc% is implied 3% the set "! GD, "$er R in 6hich the le!t side is ke% "! R( ;0( =hat is D"main-Ke% N"rmal G"rm] 168 relati"n is said t" 3e in DKNG i! all c"nstraints and dependencies that sh"uld h"ld "n the the c"nstraint can 3e en!"rced 3% simpl% en!"rcing the d"main c"nstraint and ke% c"nstraint "n the relati"n( ;2( =hat are partial, alternate,, arti!icial, c"mp"und and natural ke%] :. Partial 8e.: -t is a set "! attri3utes that can uni8uel% identi!% 6eak entities and that are related t" same "6ner entit%( -t is s"metime called as Discriminat"r( <. <ernate 8e.: ll &andidate Ke%s e9cluding the )rimar% Ke% are kn"6n as lternate Ke%s( =. &rtificial 8e.: -! n" "3$i"us ke%, either stand al"ne "r c"mp"und is a$aila3le, then the last res"rt is t" simpl% create a ke%, 3% assigning a uni8ue num3er t" each rec"rd "r "ccurrence( Then this is kn"6n as de$el"ping an arti!icial ke%( >. Com2o#nd 8e.: -! n" single data element uni8uel% identi!ies "ccurrences 6ithin a c"nstruct, then c"m3ining multiple elements t" create a uni8ue identi!ier !"r the c"nstruct is kn"6n as creating a c"mp"und ke%( ?. (at#ral 8e.: =hen "ne "! the data elements st"red 6ithin a c"nstruct is utiliFed as the primar% ke%, then it is called the natural ke%( ;3( =hat is inde9ing and 6hat are the di!!erent kinds "! inde9ing] -nde9ing is a techni8ue !"r determining h"6 8uickl% speci!ic data can 3e !"und( T%pesB 0( 1inar% search st%le inde9ing 2( 1-Tree inde9ing 3( -n$erted list inde9ing 169 :( Mem"r% resident ta3le ;( Ta3le inde9ing ;:( =hat is s%stem catal"g "r catal"g relati"n] A"6 is 3etter kn"6n as] RD1MS maintains a descripti"n "! all the data that it c"ntains, in!"rmati"n a3"ut e$er% relati"n and inde9 that it c"ntains( This in!"rmati"n is st"red in a c"llecti"n "! relati"ns maintained 3% the s%stem called metadata( -t is als" called data dicti"nar%( ;;( =hat is meant 3% 8uer% "ptimiFati"n] The phase that identi!ies an e!!icient e9ecuti"n plan !"r e$aluating a 8uer% that has the least estimated c"st is re!erred t" as 8uer% "ptimiFati"n( ;6( =hat is dura3ilit% in D1MS] +nce the D1MS in!"rms the user that a transacti"n has success!ull% c"mpleted, its e!!ects sh"uld persist e$en i! the s%stem crashes 3e!"re all its changes are re!lected "n disk( This pr"pert% is called dura3ilit%( ;<( =hat d" %"u mean 3% at"micit% and aggregati"n] :. &tomicit.: /ither all acti"ns are carried "ut "r n"ne are( #sers sh"uld n"t ha$e t" 6"rr% a3"ut the e!!ect "! inc"mplete transacti"ns( D1MS ensures this 3% und"ing the acti"ns "! inc"mplete transacti"ns( <. &--re-ation: c"ncept 6hich is used t" m"del a relati"nship 3et6een a c"llecti"n "! entities and relati"nships( -t is used 6hen 6e need t" e9press a relati"nship am"ng relati"nships( ;>( =hat is a )hant"m Deadl"ck] -n distri3uted deadl"ck detecti"n, the dela% in pr"pagating l"cal in!"rmati"n might cause the deadl"ck detecti"n alg"rithms t" identi!% deadl"cks that d" n"t reall% e9ist( Such situati"ns are called phant"m deadl"cks and the% lead t" unnecessar% a3"rts( 170 ;?( =hat is a checkp"int and =hen d"es it "ccur] &heckp"int is like a snapsh"t "! the D1MS state( 1% taking checkp"ints, the D1MS can reduce the am"unt "! 6"rk t" 3e d"ne during restart in the e$ent "! su3se8uent crashes( 60( =hat are the di!!erent phases "! transacti"n] Di!!erent phases are 0(' nal%sis phase, 2(' Red" )hase, 3(' #nd" phase( 60( =hat d" %"u mean 3% !lat !ile data3ase] -t is a data3ase in 6hich there are n" pr"grams "r user access languages( -t has n" cr"ss-!ile capa3ilities 3ut is user-!riendl% and pr"$ides user-inter!ace management( 62( =hat is Rtransparent D1MSR] -t is "ne, 6hich keeps its )h%sical Structure hidden !r"m user( 63( =hat is a 8uer%] 8uer% 6ith respect t" D1MS relates t" user c"mmands that are used t" interact 6ith a data 3ase( The 8uer% language can 3e classi!ied int" data de!initi"n language and data manipulati"n language( 6:( =hat d" %"u mean 3% &"rrelated su38uer%] Su38ueries, "r nested 8ueries, are used t" 3ring 3ack a set "! r"6s t" 3e used 3% the parent 8uer%( Depending "n h"6 the su38uer% is 6ritten, it can 3e e9ecuted "nce !"r the parent 8uer% "r it can 3e e9ecuted "nce !"r each r"6 returned 3% the parent 8uer%( -! the su38uer% is e9ecuted !"r each r"6 "! the parent, this is called a c"rrelated su38uer%( c"rrelated su38uer% can 3e easil% identi!ied i! it c"ntains an% re!erences t" the parent su38uer% c"lumns in its =A/R/ clause( &"lumns !r"m the su38uer% cann"t 3e re!erenced an%6here else in the parent 8uer%( The !"ll"6ing e9ample dem"nstrates a n"n-c"rrelated su38uer%( 171 /9ampleB Select Q Gr"m &#ST =here I0040340??0I -N (Select +DT/ Gr"m +RD/R =here &#ST(&N#M S +RD/R(&N#M' 6;( =hat are the primiti$e "perati"ns c"mm"n t" all rec"rd management s%stems] dditi"n, deleti"n and m"di!icati"n( 66( Name the 3u!!er in 6hich all the c"mmands that are t%ped in are st"red] I/ditI 1u!!er( 6<( =hat are the unar% "perati"ns in Relati"nal lge3ra] )R+D/&T-+N and S/2/&T-+N( 6>( re the resulting relati"ns "! )R+D#&T and D+-N "perati"n the same] N"( )R+D#&TB &"ncatenati"n "! e$er% r"6 in "ne relati"n 6ith e$er% r"6 in an"ther( D+-NB &"ncatenati"n "! r"6s !r"m "ne relati"n and related r"6s !r"m an"ther( 6?( =hat is RD1MS K/RN/2] T6" imp"rtant pieces "! RD1MS architecture are the kernel, 6hich is the s"!t6are, and the data dicti"nar%, 6hich c"nsists "! the s%stem-le$el data structures used 3% the kernel t" manage the data3ase H"u might think "! an RD1MS as an "perating s%stem ("r set "! su3s%stems', designed speci!icall% !"r c"ntr"lling data accessN its primar% !uncti"ns are st"ring, retrie$ing, and securing data( n RD1MS maintains its "6n list "! auth"riFed users and their ass"ciated pri$ilegesN manages mem"r% caches and pagingN c"ntr"ls l"cking !"r c"ncurrent res"urce usageN dispatches and schedules user re8uestsN and manages space usage 6ithin its ta3le-space structures( <0( Name the su3-s%stems "! a RD1MS( -4+, Securit%, 172 2anguage )r"cessing, )r"cess &"ntr"l, St"rage Management, 2"gging and Rec"$er%, Distri3uti"n &"ntr"l, Transacti"n &"ntr"l, Mem"r% Management, 2"ck Management( <0( =hich part "! the RD1MS takes care "! the data dicti"nar%] A"6] Data dicti"nar% is a set "! ta3les and data3ase "3@ects that is st"red in a special area "! the data3ase and maintained e9clusi$el% 3% the kernel( <2( =hat is the @"3 "! the in!"rmati"n st"red in data-dicti"nar%] The in!"rmati"n in the data dicti"nar% $alidates the e9istence "! the "3@ects, pr"$ides access t" them, and maps the actual ph%sical st"rage l"cati"n( <3( A"6 d" %"u c"mmunicate 6ith an RD1MS] H"u c"mmunicate 6ith an RD1MS using Structured 7uer% 2anguage (S72'( <:( De!ine S72 and state the di!!erences 3et6een S72 and "ther c"n$enti"nal pr"gramming 2anguages( S72 is a n"npr"cedural language that is designed speci!icall% !"r data access "perati"ns "n n"rmaliFed relati"nal data3ase structures( The primar% di!!erence 3et6een S72 and "ther c"n$enti"nal pr"gramming languages is that S72 statements speci!% 6hat data "perati"ns sh"uld 3e per!"rmed rather than h"6 t" per!"rm them( <;( Name the three ma@"r set "! !iles "n disk that c"mp"se a data3ase in +racle( There are three ma@"r sets "! !iles "n disk that c"mp"se a data3ase( ll the !iles are 3inar%( These are 173 0(' Data3ase !iles 2(' &"ntr"l !iles 3(' Red" l"gs The m"st imp"rtant "! these are the data3ase !iles 6here the actual data resides( The c"ntr"l !iles and the red" l"gs supp"rt the !uncti"ning "! the architecture itsel!( ll three sets "! !iles must 3e present, "pen, and a$aila3le t" +racle !"r an% data "n the data3ase t" 3e usea3le( =ith"ut these !iles, %"u cann"t access the data3ase, and the data3ase administrat"r might ha$e t" rec"$er s"me "r all "! the data3ase using a 3ackup, i! there is "ne( <6( =hat is data3ase Trigger] data3ase trigger is a )24S72 3l"ck that can de!ined t" aut"maticall% e9ecute !"r insert, update, and delete statements against a ta3le( The trigger can e de!ined t" e9ecute "nce !"r the entire statement "r "nce !"r e$er% r"6 that is inserted, updated, "r deleted( G"r an% "ne ta3le, there are t6el$e e$ents !"r 6hich %"u can de!ine data3ase triggers( data3ase trigger can call data3ase pr"cedures that are als" 6ritten in )24S72( <<( =hat are st"red-pr"cedures] nd 6hat are the ad$antages "! using them] St"red pr"cedures are data3ase "3@ects that per!"rm a user de!ined "perati"n( st"red pr"cedure can ha$e a set "! c"mp"und S72 statements( st"red pr"cedure e9ecutes the S72 c"mmands and returns the result t" the client( St"red pr"cedures are used t" reduce net6"rk tra!!ic( <>( =hat is St"rage Manager] -t is a pr"gram m"dule that pr"$ides the inter!ace 3et6een the l"6-le$el data st"red in data3ase, applicati"n pr"grams and 8ueries su3mitted t" the s%stem( <?( =hat is 1u!!er Manager] -t is a pr"gram m"dule, 6hich is resp"nsi3le !"r !etching data !r"m disk st"rage int" main mem"r% and deciding 6hat data t" 3e cache in mem"r%( >0( =hat is Transacti"n Manager] -t is a pr"gram m"dule, 6hich ensures that data3ase, remains in a c"nsistent state despite s%stem !ailures and c"ncurrent transacti"n e9ecuti"n pr"ceeds 6ith"ut c"n!licting( 174 >0( =hat is Gile Manager] -t is a pr"gram m"dule, 6hich manages the all"cati"n "! space "n disk st"rage and data structure used t" represent in!"rmati"n st"red "n a disk( >2( =hat is uth"riFati"n and -ntegrit% manager] -t is the pr"gram m"dule, 6hich tests !"r the satis!acti"n "! integrit% c"nstraint and checks the auth"rit% "! user t" access data( >3( =hat are stand-al"ne pr"cedures] )r"cedures that are n"t part "! a package are kn"6n as stand-al"ne 3ecause the% independentl% de!ined( g""d e9ample "! a stand-al"ne pr"cedure is "ne 6ritten in a S72QG"rms applicati"n( These t%pes "! pr"cedures are n"t a$aila3le !"r re!erence !r"m "ther +racle t""ls( n"ther limitati"n "! stand-al"ne pr"cedures is that the% are c"mpiled at run time, 6hich sl"6s e9ecuti"n( >:( =hat are curs"rs gi$e di!!erent t%pes "! curs"rs] )24S72 uses curs"rs !"r all data3ase in!"rmati"n accesses statements( The language supp"rts the use t6" t%pes "! curs"rs 0(' -mplicit 2(' /9plicit >;( =hat is c"ld 3ackup and h"t 3ackup (in case "! +racle'] 0( &"ld 1ackupB -t is c"p%ing the three sets "! !iles (data3ase !iles, red" l"gs, and c"ntr"l !ile' 6hen the instance is shut d"6n( This is a straight !ile c"p%, usuall% !r"m the disk directl% t" tape( H"u must shut d"6n the instance t" guarantee a c"nsistent c"p%( -! a c"ld 3ackup is per!"rmed, the "nl% "pti"n a$aila3le in the e$ent "! data !ile l"ss is rest"ring all the !iles !r"m the latest 3ackup( ll 6"rk per!"rmed "n the data3ase since the last 3ackup is l"st( 2( A"t 1ackupB S"me sites (such as 6"rld6ide airline reser$ati"ns s%stems' cann"t shut d"6n the data3ase 6hile making a 3ackup c"p% "! the !iles( The c"ld 3ackup is n"t an a$aila3le "pti"n( >6( =hat is meant 3% )r"acti$e, Retr"acti$e and Simultane"us #pdate( 0( )r"acti$e #pdateB The updates that are applied t" data3ase 3e!"re it 3ec"mes e!!ecti$e in real 6"rld( 175 2( Retr"acti$e #pdateB The updates that are applied t" data3ase a!ter it 3ec"mes e!!ecti$e in real 6"rld( 3( Simulatne"us #pdateB The updates that are applied t" data3ase at the same time 6hen it 3ec"mes e!!ecti$e in real 6"rld( SU##L,M,NT - B )&T&B&SE &PP,C&TO( Em2lo.ee" Mana-ement &22lication This applicati"n is used t" keep track "! in!"rmati"n a3"ut empl"%ees "! a c"mpan%( -t als" st"res the in!"rmati"n a3"ut departments and lea$es taken 3% empl"%ees( H"u are re8uired t" create ta3les (as sh"6n 3el"6' and insert data int" each "! the ta3le( part !r"m gi$ing %"u an idea a3"ut h"6 t" create ta3les 6ith c"nstraints, it als" ena3les %"u t" understand h"6 t" create 8ueries, pl4s8l pr"grams, st"red pr"cedures and !uncti"ns and data3ase triggers( A"6e$er, n"te, this sample c"llecti"n "! ta3les is "nl% !"r learning purp"se and the% are h%p"thetical( Re8uired Ta3les Structure "! Ta3les 176 &reating Ta3les 2"ading data int" ta3les 7ueries Re;#ired Ta$le" The !"ll"6ing are the set "! ta3les t" 3e created t" st"re the re8uired in!"rmati"n( Ta$le (ame Meanin- D/)T St"res the details "! departments "! the c"mpan%( /M)2+H// St"res in!"rmati"n a3"ut all the empl"%ees "! the c"mpan%( 2/./S St"res in!"rmati"n a3"ut t%pes "! lea$es a$aila3le /M)P2/./S St"res in!"rmati"n a3"ut lea$es taken 3% the empl"%ees( Structure "! Ta3les The !"ll"6ing is the structure "! each "! the re8uired ta3le( D/)T Ta3le St"res in!"rmati"n a3"ut all the departments "! the c"mpan%( Col#mn (ame )atat.2e Meanin- D/)TN+ num3er(2' Department Num3er D/)TNM/ $archar2(20' Department Name A+D $archar2(20' Aead "! the department Con"traint" D/)TN+ is primar% ke% D/)TNM/ must 3e uni8ue 177 EMP,OHEE ta$le &"ntains in!"rmati"n a3"ut all the empl"%ees "! the c"mpan%( Col#mn (ame )atat.2e Meanin- /M)N+ num3er(;' /mpl"%ee Num3er /M)NM/ $archar2(20' /mpl"%ee Name S2 num3er(6' 1asic Salar% D/)TN+ num3er(2' Department t" 6hich empl"%ee 3el"ngs DD Date Date "! @"ining the c"mpan% D/S, $archar2(20' Designati"n "! the empl"%ee Con"traint" /M)N+ is primar% ke% S2 must 3e VS 0000 D/)TN+ is !"reign ke% re!erencing D/)TN+ "! D/)T ta3le ,E&!ES Ta$le &"ntains in!"rmati"n a3"ut the t%pes "! lea$es a$aila3le in the c"mpan%( Col#mn (ame )atat.2e Meanin- 2/./TH)/ char(0' &"de !"r the t%pe "! lea$e 2/./NM/ $archar2(20' Descripti"n "! the t%pe "! the lea$e N+2/./S num3er(2' Num3er "! lea$es all"tted t" each empl"%ee !"r a lea$e t%pe Contraint" 2/./TH)/ is primar% ke% N+2/./S must 3e US 20 EMPF,E&!ES Ta$le &"ntains in!"rmati"n a3"ut the lea$es taken 3% empl"%ees( 178 Col#mn (ame )atat.2e Meanin- /M)N+ num3er(;' /mpl"%ee num3er "! the empl"%ee 6h" has taken lea$e 2/./TH)/ char(0' T%pe "! the lea$e taken 3% the empl"%ee STDT/ Date Starting date "! the lea$e /NDDT/ Date /nding date "! the lea$e Contraint" /M)N+ C STDT/ is primar% ke% 2/./TH)/ is n"t null /M)N+ is !"reign ke% re!erencing /M)N+ in /M)2+H//S ta3le 2/./TH)/ is !"reign ke% re!erencing 2/./TH)/ in 2/./S ta3le STDT/ must 3e US /NDDT/ Creatin- Ta$le" The !"ll"6ing scirpt is used t" create sample ta3les( &lick here t" d"6nl"ad the script and run the script at S72V pr"mt using STRT c"mmand "! S72Q)2#SV R/M QQQQQQ script t" create ta3les realted t" /M)2+H//S applicati"n QQQQQQ R/M QQQQQQ #TA+R B )(SR-KNTA QQQQQQ R/M QQQQQQ DT/ B 23-#,-2000 QQQQQQ R/M QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ dr"p ta3le empPlea$es cascade c"nstraintsN dr"p ta3le empl"%ee cascade c"nstraintsN dr"p ta3le dept cascade c"nstraintsN dr"p ta3le lea$es cascade c"nstraintsN &R/T/ T12/ D/)T ( D/)TN+ N#M1/R(2' &+NSTR-NT D/)TP)K )R-MRH K/H, D/)TNM/ .R&AR2(20' &+NSTR-NT D/)TPD/)TNM/P# #N-7#/, A+D .R&AR2(20' 'N &R/T/ T12/ 2/./S ( 2/./TH)/ &AR(0' &+NSTR-NT 2/./SP)K )R-MRH K/H, 2/./NM/ .R&AR2(20', 179 N+2/./S N#M1/R(2' &+NSTR-NT 2/./SPN+2/./SP&AK &A/&K ( N+2/./S US 20' 'N &R/T/ T12/ /M)2+H// ( /M)N+ N#M1/R(;' &+NSTR-NT /M)2+H//P)K )R-MRH K/H, /M)NM/ .R&AR2(20', S2 N#M1/R(;' &+NSTR-NT /M)2+H//PS2P&AK &A/&K ( S2 VS 0000', D/)TN+ N#M1/R(2' &+NSTR-NT /M)2+H//PD/)TN+PGK R/G/R/N&/S D/)T(D/)TN+', D/S, .R&AR2(20', DD DT/, 'N &R/T/ T12/ /M)P2/./S ( /M)N+ N#M1/R(;' &+NSTR-NT /M)P2/./SP/M)N+PGK R/G/R/N&/S /M)2+H//(/M)N+', 2/./TH)/ &AR(0' &+NSTR-NT /M)P2/./SP2/./TH)/PGK R/G/R/N&/S 2/./S(2/./TH)/' &+NSTR-NT /M)P2/./SP2/./TH)/PNN N+T N#22, STDT/ DT/, /NDDT/ DT/, &+NSTR-NT /M)P2/./SP)K )R-MRH K/H (/M)N+,STDT/', &+NSTR-NT /M)P2/./SPDT/SP&AK &A/&K (STDT/ US /NDDT/' 'N 2"ading data int" ta3les The !"ll"6ing script inserts a !e6 r"6s int" sample ta3les( &lick here t" d"6nl"ad the script t" create sample data "r c"p% the script gi$en 3el"6 int" n"tepad, sa$e it 6ith (S72 e9tensi"n and run it at S72V using STRT c"mmand( R/M QQQQQQ script t" insert sample data int" /M)2+H//S applicati"n QQQQQQ R/M QQQQQQ #TA+R B )(SR-KNTA QQQQQQ R/M QQQQQQ DT/ B 23-#,-2000 QQQQQQ R/M QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ rem rem"$e all e9isting r"6s !irst D/2/T/ GR+M /M)P2/./SN D/2/T/ GR+M /M)2+H//N D/2/T/ GR+M D/)TN D/2/T/ GR+M 2/./SN -NS/RT -NT+ 2/./S .2#/S(ISI,IS-&KI,0;'N -NS/RT -NT+ 2/./S .2#/S(I&I,I&S#2I,0;'N -NS/RT -NT+ 2/./S .2#/S(I/I,I/RN-N,I,;'N -NS/RT -NT+ 2/./S .2#/S(I+I,I+./RT-M/I,;'N -NS/RT -NT+ D/)T .2#/S(0,IM-NGRM/I,I,/+R,/I'N -NS/RT -NT+ D/)T .2#/S(2,I&2-/NT4S/R./RI,I1-22I'N -NS/RT -NT+ D/)T .2#/S(3,ISHST/MSI,I,RRHI'N -NS/RT -NT+ D/)T .2#/S(:,I-NT/RN/TI,I)#2I'N -NS/RT -NT+ D/)T .2#/S(;,I&&+#NTSI,INDHI'N -NS/RT -NT+ /M)2+H// .2#/S(000,I,/+R,/I,02000,0,I02-D#2-2000I,I)MI'N -NS/RT -NT+ /M)2+H// .2#/S(002,I1-22I,02000,2,I0:-D#2-2000I,I)MI'N -NS/RT -NT+ /M)2+H// .2#/S(003,I,RRHI,0;000,3,I0-D#2-2000I,I)MI'N 180 -NS/RT -NT+ /M)2+H// .2#/S(00:,I)#2I,00000,:,I2-D#2-2000I,I)2I'N -NS/RT -NT+ /M)2+H// .2#/S(00;,INDHI,<000,;,I2;-D#N-2000I,IMI'N -NS/RT -NT+ /M)2+H// .2#/S(006,IK/TSI,00000,0,I0<-D#2-2000I,ISI'N -NS/RT -NT+ /M)2+H// .2#/S(00<,ID+/2I,>000,2,I0;-D#2-2000I,IS)I'N -NS/RT -NT+ /M)2+H// .2#/S(00>,IR+1/RTSI,<;00,2,I0;-D#2-2000I,I)R+I'N -NS/RT -NT+ /M)2+H// .2#/S(00?,IA/R1/RTI,>000,:,I22-D#2-2000I,ISI'N -NS/RT -NT+ /M)2+H// .2#/S(000,IM-&A/2I,6000,:,I0;-D#2-2000I,I)R+I'N -NS/RT -NT+ /M)P2/./S .2#/S(002,ISI,I23-D#2-2000I,I2;-D#2-2000I'N -NS/RT -NT+ /M)P2/./S .2#/S(00:,I&I,I2:-D#2-2000I,I2;-D#2-2000I'N -NS/RT -NT+ /M)P2/./S .2#/S(00:,ISI,I2>-D#2-2000I,I2?-D#2-2000I'N -NS/RT -NT+ /M)P2/./S .2#/S(000,I&I,I2<-D#2-2000I,I2>-D#2-2000I'N -NS/RT -NT+ /M)P2/./S .2#/S(006,I+I,I2>-D#2-2000I,I2?-D#2-2000I'N -NS/RT -NT+ /M)P2/./S .2#/S(00?,I&I,I0-#,-2000I,I2-#,-2000I'N -NS/RT -NT+ /M)P2/./S .2#/S(003,I&I,I2-#,-2000I,I;-#,-2000I'N -NS/RT -NT+ /M)P2/./S .2#/S(00;,ISI,I0<-#,-2000I,N#22'N -NS/RT -NT+ /M)P2/./S .2#/S(00>,ISI,I23-#,-2000I,N#22'N &+MM-TN $uer"es +elated To ,m(lo'ees Management A((l"cat"on +: D-S)2H /M)2+H//S =A+ A./ D+-N/D -N TA/ 2ST 0; DHS S/2/&T Q GR+M /M)2+H// =A/R/ SHSDT/ - DD US 0;N +: D-S)2H /M)2+H//S =A+ A./ D+-N/D T+DH S/2/&T Q GR+M /M)2+H// =A/R/ TR#N&(SHSDT/' S TR#N&(DD'N (OTE: TR#N& G#N&T-+N -S R/7#-R/D -N +RD/R T+ -,N+R/ T-M/ D-GG/R/N&/ 1/T=//N T=+ DT/S( +: D-S)2H =A+ A./ D+-N/D -N TA/ 2ST =//K +G TA/ M+NTA S/2/&T Q GR+M /M)2+H// =A/R/ DD VS 2STPDH(DD' - <N +: D-S)2H =A/N /M)2+H// 002 AS TK/N A-S G-RST S2RH S/2/&T /M)NM/, 2STPDH(DD' C 0 RG-RST S2RH DT/R GR+M /M)2+H// =A/R/ /M)N+ S 002N +: D/2/T/ /M)2+H//S =A+ A./ D+-N/D TA/ &#RR/NT M+NTA D/2/T/ GR+M /M)2+H// =A/R/ T+P&AR(SHSDT/,IMMHHHHI' S T+P&AR(DD,IMMHHHHI' 181 +: D/T-2S +G /M)2+H//S =A+S/ S2RH RN,/ -S 1/T=//N 02,000 T+ 0:,000 S/2/&T Q GR+M /M)2+H// =A/R/ S2 1/T=//N 02000 ND 0:000N +: D/T-2S +G /M)2+H//S =A+ 1/2+N, T+ D/)RTM/NT 0 +R 3 S/2/&T Q GR+M /M)2+H// =A/R/ D/)TN+ -N (0,3'N +: S/2/&T NM/S +G /M)2+H//S =A+S/ NM/S STRT =-TA IMI S/2/&T /M)NM/ GR+M /M)2+H// =A/R/ /M)NM/ 2-K/ IM_IN +: D/2/T/ TA+S/ /M)2+H//S =A/R/ NM/ AS TA/ &AR&T/R II D/2/T/ GR+M /M)2+H// =A/R/ /M)NM/ 2-K/ I__IN +: S/2/&T /M)2+H//S =A/R/ S/&+ND &AR&T/R -N NM/ -S ISI S/2/&T Q GR+M /M)2+H// =A/R/ /M)NM/ 2-K/ IPS_IN +: S/2/&T TA+S/ /M)2+H//S =A+S/ S2RH -S N+T KN+=N S/2/&T Q GR+M /M)2+H// =A/R/ S2 -S N#22N +: D-S)2H TA/ D/T-2S +G /M)2+H//S =A+ A./ D+-N/D -N TA/ 2ST 20 DHS S/2/&T Q GR+M /M)2+H// =A/R/ SHSDT/ - DD US 20N +: D-S)2H TA/ D/T-2S +G 2/./S -G TA/ N#M1/R +G 2/./S -S M+R/ TAN 00 S/2/&T Q GR+M /M)P2/./S =A/R/ /NDDT/ - STDT/ V 00N +: D-S)2H /M)N+,/M)NM/,DT/ +G D+-N-N,,N#M1/R +G M+NTAS +G /E)/R-/N&/ ND 1S-& S2RH S/2/&T /M)N+, /M)NM/, DD, M+NTASP1/T=//N(SHSDT/,DD' /E), S2 GR+M /M)2+H//N +: D-S)2H D/T-2S +G /M)2+H//S =A+ R/ DR=-N, M+R/ TAN 00000 ND TA/ D/S-,NT-+N -S &+NT-N-N, M+R/ TAN 3 2/TT/RS S/2/&T Q GR+M /M)2+H// =A/R/ S2 V 00000 ND 2/N,TA(D/S,' V 3N +: D-S)2H D/T-2S +G /M)2+H//S =A+S/ NM/ -S &+NT-N-N, M+R/ TAN +N/ S)&/ 182 S/2/&T Q GR+M /M)2+H// =A/R/ -NSTR(/M)NM/, I I , 0, 2' UV 0N +: D-S)2H D/T-2S +G 2/./S =A/R/ TA/ 2/./ STRT/D -N TA/ )R/.-+#S M+NTA ND TA/ 2/./ -S N+T H/T &+M)2/T/D S/2/&T Q GR+M /M)P2/./S =A/R/ STDT/ 1/T=//N 2STPDH( DDPM+NTAS(STDT/,-2'' C 0 ND 2STPDH( DDPM+NTAS(STDT/,-0'' C 0 ND /NDDT/ -S N#22N +: D-S)2H D/T-2S +G /M)2+H//S =A/R/ 1S-& S2RH -S M+R/ TAN 00000 +R D/S-,NT-+N -S )2 ND /E)/R-/N&/ -S M+R/ TAN 3 H/RS S/2/&T Q GR+M /M)2+H// =A/R/ S2 V 00000 +R D/S, S I)2I ND M+NTASP1/T=//N(SHSDT/,DD' V 36N