You are on page 1of 56

TE102/Datbase Management Systems

Course Name: Database Management Systems Course Code: TE102 Assignment Type: DBMS Lecture otes

Database Management Systems


Data are ra! "acts !#ic# can be manipu$ated% Data is re&uired in t#e operation o" any organi'ation( and t#e same or simi$ar data may be re&uired "or )arious purposes% Information is t#e manipu$ation o" data% *n t#e ot#er !ords( in"ormation is t#e summari'ation o" data in a presentab$e "orm% Data consists o" "acts( !#ic# become information !#en t#ey are processed and con)ey meaning to peop$e% A database is an organi'ed co$$ection o" "acts% *n ot#er !ords !e can say t#at it is a co$$ection o" in"ormation arranged and presented to ser)e an assigned purpose% As e+amp$e o" a database is a dictionary( !#ere !ords are arranged a$p#abetica$$y% T#us in"ormation stored in a database is arranged in a particu$ar order% A database management system ,DBMS-( or simp$y a database system ,DBS-( consists o" o o A co$$ection o" interre$ated and persistent data ,usua$$y re"erred to as t#e database ,DB--% A set o" app$ication programs used to access( update and manage t#at data ,!#ic# "orm t#e data management system ,MS--% T#e goa$ o" a DBMS is to pro)ide an en)ironment t#at is bot# convenient and efficient to use in o o .etrie)ing in"ormation "rom t#e database% Storing in"ormation into t#e database%

Databases are usua$$y designed to manage large bodies o" in"ormation% T#is in)o$)es o De"inition o" structures "or in"ormation storage ,data mode$ing-% o o o /ro)ision o" mec#anisms "or t#e manipu$ation o" in"ormation ,"i$e and systems structure( &uery processing-% /ro)iding "or t#e sa"ety o" in"ormation in t#e database ,cras# reco)ery and security-% Concurrency contro$ i" t#e system is s#ared by users%
A dreamMAKERS *nitiati)e

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

S!" SBL is standard $anguage "or ma5ing &ueries in re$ationa$ database pac5ages suc# as SBL ser)er( *ngress( Sybase( Crac$e etc% T#e C.ACLE system uses non3procedura$ Structured Buery Language to communicate !it# its database 5erne$% *n 19A;( t#e American ationa$ Standard *nstitute ,A S*- made SBL t#e standard "or a$$ DBMS% *t1s a po!er"u$ &uery $anguage and a$$ t#e app$ications de)e$opment too$s t#at C.ACLE pro)ides are SBL based% SBL is a non3procedura$ $anguage since on$y t#e tas5 t#at #as to be ac#ie)ed is speci"ied( not #o! to go about doing t#e Dob i%e% it pro)ides automatic na)igation to t#e data% T#e records are processed set at a time rat#er t#an Dust a record at a time% SBL does not support any programming $anguage constructs $i5e i"%%e$se or !#i$e etc( but can be embedded in ot#er programming $anguages $i5e C( CCBCL( /L/ or ADA T#ere are t!o types o" SBL: 1- *nteracti)e SBL 2- Embedded SBL

*nteracti)e SBL is used to operate direct$y on a database to produce output "or our purpose% Embedded SBL consists o" SBL commands put inside programs t#at are most$y !ritten in some ot#er #ig# $e)e$ $anguage% T#is met#od can ma5e t#e program more po!er"u$ and e""icient%

#eatures of S!"
*t1s an interacti)e &uery $anguage t#at a$$o!s t#e users to use SBL statements to retrie)e data and disp$ay it o t#e screen% *t1s a database programming $anguage t#at a$$o!s programmer to embed SBL statements in @EL programs to access data in a database% *t1s a database administration $anguage t#at de"ines t#e structure o" t#e database and contro$s t#e user access to data% *t1s a c$ient/ser)er $anguage t#at a$$o!s app$ication programs on /Cs connected )ia LA communicate !it# t#e database ser)ers t#at store s#ared data% *t1s a database gate!ay $anguage and o"ten used in gate!ay t#at a$$o!s one brand o" DBMS to communicate !it# anot#er brand%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

to

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

S!"$%"&S
SBLF/L2S is po!er"u$ C.ACLE support t#at can ta5e your instructions "or orac$e% T#is "$e+ib$e too$ a$$o!s bot# de)e$opers and end3user to issue SBL commands direct$y against t#e database% Database de)e$opers use SBLF/L2S to create( "i$$ and monitor an app$ication1s database% End3 users o" t#e database use it to per"orm ad #oc &ueries against t#e database% Basica$$y SBLF/L2S is a command $ine interpreter% Commands issued in SBLF/L2S are bro5en into t!o distinct groups: t#e A S* standards SBL commands to create( monitor and manipu$ate an app$ication1s databaseG and t#e SBLF/L2S commands pro)ided by C.ACLE to en#ance t#e "unctiona$ity o" t#e A S* standards SBL commands% SBLF/L2S commands contro$ t#e SBLF/L2S en)ironment( "ormat t#e output o" SBL commands( and contro$ database transaction processing% SBLF/L2S pro)ides an open port to t#e database% An open port gi)es users( depending upon t#eir access pri)i$eges to speci"ic tab$es in a database unrestrained access to t#e database1s data% =#en user issues a command( it direct$y a""ects t#e data in t#e database% Se)era$ $e)e$s o" access security pre)ent SBLF/L2S and user "rom &ueuing and modi"ying e)ery tab$e in t#e database% Eac# user runs SBLF/L2S !it# a speci"ic user name !it# a speci"ic $e)e$ o" database access% Hurt#ermore( a security access is p$aced on eac# database tab$e( restricting user "rom &uering and modi"ying ot#er user1s tab$e !it#out proper aut#ori'ation%

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Data 'ypes
=#en you create tab$e in SBLF/L2S( you must speci"y t#e type o" data t#at may appear in eac# co$umn% Some o" t#e common data types are $isted be$o!% Data 'ype Command C>A.,si'eDescription Hi+ed $engt# c#aracter data% Si'e !ritten in t#e brac5et determines t#e $engt# o" data t#at can be stored% De"au$t si'e is 1 and ma+imum si'e is 288% Iariab$e $engt# c#aracter string #a)ing ma+imum $engt# si'e in bytes% Ma+imum si'e is 2000% Si'e must be speci"ied% 2sed to store )ariab$e $engt# numeric data% / determines t#e tota$ number o" digits possib$e to t#e $e"t o" decima$ point% S determines t#e tota$ number o" digits possib$e to t#e rig#t o" decima$ point% Hi+ed point number !it# precision si'e and sca$e 0%

C#aracter IA.C>A.2 ,si'e2MBE.,p(sumber 2MBE. ,si'eDATE

Date

Long

LC E

.a!

.A=,si'e-

T#is data type is used to store data and time in"ormation% De"au$t "ormat is DD3MC 3JJ% To enter t#e dates ot#er t#an standard "ormat( use t#e appropriate "unctions% Iariab$e $engt# c#aracter strings containing up to 2 gigabytes% Tab$e cannot #a)e more t#an one Long type o" data "ie$d% *t cannot be inde+ed% *t cannot be used !it# SBL "unction% *t cannot appear in =>E.E( E.C2/ BJ( C.EE. BJ( c$auses% .a! binary data( si'e byte $ong% Ma+imum si'e is 288 bytes%

CREA'IN( A 'A)"E IN '*E DA'A)ASE S&$KCreate table tab$ename,co$umn 1 datatype,si'e- Lde"au$t Me+prKN LCC ST.A* T constraint nameN Lco$umnOconstraintN( Co$umn 2 datatype,si'e-P%%-G Hor e+amp$e: S&$KCreate table c$ientOmaster
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

, cOno )arc#ar2,8-( name )arc#ar2,10-( address )arc#ar2,20-( pincode number,;-( ba$Odue number,10(2--G INSER'IN( DA'A IN' '*E 'A)"ES

T#e * SE.T command !it# t#e )a$ues c$ause is used to add ne! ro!s to a database tab$e%

S&$K INSER' IN' Hor e+amp$e:

tab$enameL,co$umn1( co$umn 2P-N +A"&ES ,)a$ue1( )a$ue2(%%-G

S&$K INSER' IN' c$ientOmaster ,cOno( name( address( pincode( ba$Odue+A"&ES ,QC0011( QADay1( QA38( B#andu1( @A<120( 800 -G DA'A RE'RI+A" &SIN( S!" $%"&S SBLF/L2S pro)ides a &uery capabi$ity in t#e "orm o" SELECT statement% Cne can )ie! t#e current in"ormation in t#e tab$es by using t#is statement% T#e SELECT statement can be used to Disp$ay some or a$$ t#e co$umns "rom a speci"ied tab$e% Disp$ay some or a$$ o" t#e ro!s "rom a speci"ied tab$e% Disp$ay ca$cu$ated )a$ues "rom t#e tab$e% Disp$ay statistica$ in"ormation "rom t#e tab$es( $i5e a)erages or sums o" co$umn )a$ues% Combine in"ormation "rom t!o or more tab$es% Displaying some or all t,e Columns from a 'able S&$K SE"EC' co$umn1( co$umn2(PP #R M tab$enameG S&$K SE"EC' cOno( name #R M c$ientOmasterG S&$K SE"EC' $ #R M tab$enameG S&$K SE"EC' $ #R M c$ientOmasterG Note: T#e SELECT c$ause "o$$o!ed by t#e H.CM c$ause are re&uired "or any SBL &uery% ot a$$ co$umns need to be se$ected% Co$umns are disp$ayed $e"t or rig#t in t#e order speci"ied% SELECT $ist items must be separated by commas% .o!s are returned in an arbitrary manner% 2sers may &uery on$y tab$es t#ey #a)e created or tab$es to !#ic# t#ey #a)e granted access% *" you !ant to see !#ic# tab$es you #a)e in your account( a specia$ &uery can be madeP
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

S&$K SE"EC'$ #R M tab Displaying Some Specified Ro.s from t,e 'able *" you !ant conditiona$ retrie)a$ o" ro!s i%e% on$y t#ose ro!s !#ic# satis"y certain condition% Jou can use =>E.E c$ause in t#e SELECT statement% s&$KSE"EC' co$umn $ist #R M tab$ename /*ERE conditionG s&$KSE"EC' cOno( name #R M c$ientOmaster /*ERE ba$OdueK800G Note: Co$umns speci"ied n t#e =>E.E c$ause must be part o" t#e tab$e speci"ied in t#e "orm c$ause% Co$umns used in t#e =>E.E c$ause do not #a)e to be in SELECT $ist% T#e =>E.E c$ause must speci"y c#aracter data in t#e same case ,upper or $o!er- t#at it is in t#e database% T#e comparison operators t#at can be used in SBL statements M ( K ( MR %%( KR ( R ( MK Elimination of duplicates from t,e select statement: A tab$e cou$d #o$d dup$icate ro!s% *n suc# a case( to see on$y uni&ue ro!s t#e synta+ is: S&$KSE"EC' DIS'INC' co$umnname( co$umnname #R M tab$enameG S&$KSE"EC' DIS'INC' Dob #R M emp$oyee S&$KSE"EC' DIS'INC' $ #R M tab$enameG S&$KSE"EC' DIS'INC' $ #R M c$ientOmasterCRE'IN( 'A)"E #R M A 'A)"E S&$KCREA'E 'A)"E tab$enameL,co$umnname( co$umnname-N AS SE"EC' co$umnname( co$umnname #R M tab$enameG S&$K CREA'E 'A)"E supp$ierOmaster ,sOno( sOname( address( pincode( ba$OdueC2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

AS SE"EC' cOno( name( address( pincode( ba$Odue #R M c$ientOmasterG T#e source tab$e is a tab$e identi"ied in t#e se$ect section o" t#is SBL sentence% T#e target tab$e is one identi"ied in t#e create section o" t#is SBL sentence% INSER'IN( DA'A IN' A 'A)"E #R M AN '*ER 'A)"E

To insert data one ro! at a time into a tab$e( it is &uite possib$e to popu$ate a tab$e !it# data t#at a$ready e+ists in anot#er tab$e% S&$K INSER' IN' tab$ename SE"EC' co$umnname( co$umnname( #R M tab$enameG S&$K INSER' IN' supp$ierOmaster SE"EC' cOno( name( address( pincode( ba$Odue #R M c$ientOmasterG Insertion of data set into a table from anot,er table S&$KINSER' IN' one tab$ename SE"EC' co$umn1( co$umn2(P #R M ot#er tab$e 0/*ERE Condition1S&$K INSER' IN' supp$ierOmaster SE"EC' cOno( name( address( pincode( ba$Odue #R M c$ientOmasterG /*ERE cOnoR1C0011G +IE/IN( '*E S'R&C'&RE # '*E 'A)"E

Sometimes need may arise to see t#e co$umn de"inition or t#e integrity constraints speci"ied on t#em in a particu$ar tab$e% *n suc# conditions DESC.*BE "unction can be used to )ie! tab$e de"inition%

S&$K DESCRI)E tab$enameG T#is disp$ays $ist o" co$umns and t#eir respecti)e co$umn constraints "or t#e speci"ied tab$e% M DI#2IN( '*E 'A)"E DE#INI'I N To c#ange t#e "ormat o" an e+iting tab$e( !e can use ALTE. TABLE command% S&$KA"'ER 'A)"E tab$ename LMCD*HJN LADDN
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e
4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Adding Ne. Column S&$K A"'ER 'A)"E tab$ename ADD 3ne! co$umnname datatype,si'e-( ne! co$umnname datatype,si'e- -G S&$K A"'ER 'A)"E c$ientOmaster ADD ,cO"a+ number,18-( city )arc#ar2,;--G Modifying t,e E4isting Columns: S&$K A"'ER 'A)"E tab$ename M DI#2 ,co$umnname ne!datatype,ne!si'e--G S&$K A"'ER 'A)"E c$ientOmaster M DI#2 3cO"a+ )arc#ar2,10-5-

Note: =e can increase a C>A. co$umn1s !idt# or t#e number o" t#e digits number o" decima$ p$aces in t#e 2MBE. co$umn at any time% =e can c#ange t#e co$umn "rom CT 2LL TC 2LL by adding t#e 2LL c$ause to t#e end o" co$umn speci"ication% To decrease a co$umn si'e( t#e co$umn must be 2LL in a$$ e+iting ro!s% To add t#e not 2LL "eature to a co$umn( t#e co$umn must #a)e a )a$ue "or e)ery ro! in t#e tab$e% To c#ange t#e data type o" a co$umn( a$$ )a$ues in t#e co$umn must be 2LL in a$$ ro!s% To modi"y more t#an one co$umn( use command !it#in t#e parent#eses to separate eac# co$umn "rom t#e ne+t% Jou may add a co$umn at any time i" 2LL is speci"ied% Jou may not be ab$e to add a co$umn !it# CT 2LL speci"ied% Jou cannot c#ange t#e tab$e name and co$umn name% REM +IN( '*E 'A)"E #R M '*E DA'A)ASE S&$KDR % 'A)"E tab$enameG S&$KDR % 'A)"E c$ientOmasterRENAMIN( 'A)"ES S&$KRENAME 'A)"E o$d tab$e name ' S&$KRENAME 'A)"E c$ientOmaster ' ne! tab$e nameG c$ientOmaster1G
A dreamMAKERS *nitiati)e

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

M DI#2IN( '*E DA'A IN E6IS'IN( 'A)"E: S&$K &%DA'E tab$ename SE' co$umnRe+pression or )a$ue 0/*ERE Condition1S&$K &%DA'E c$ientOmaster SE' name7 QIiDay( addressR1Me#sana1 /*ERE cOno78c0011G REM +IN( R /S #R M A 'A)"E: T#e DELETE command is used to remo)e ro!s "rom a tab$e% s&$KDE"E'E #R M tab$ename 0/*ERE condition1s&$KDE"E'E #R M c$ientOmaster /*ERE ba$OdueK800G =>E.E c$ause determines !#ic# ro!s !i$$ be remo)ed% *" t#e c$ause is not speci"ied A$$ t#e ro!s "rom t#e tab$e !i$$ be de$eted% A5 'able Name: Client9master Description: 2sed to store in"ormation about c$ients% Column Name C$ientOno ame Address1 Adddress2 Ciy /incode State Ba$Odue Data 'ype Iarc#ar2 Iarc#ar2 Iarc#ar2 Iarc#ar2 Iarc#ar2 umber Iarc#ar2 umber Si:e ; 20 @0 @0 18 A 18 10(2

)5 'able Name: %roduct9master Description: 2sed to store in"ormation about products% Column Name /roductOno Description /Opercent 2Omeasure BtyOonO#and .eorderO$)$ Data 'ype Iarc#ar2 Iarc#ar2 umber Iarc#ar2 umber umber Si:e ; 18 <(2 10 A A
A dreamMAKERS *nitiati)e

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Se$$Oprice CostOprice

umber umber

A(2 A(2

C5 'able Name: Salesman9master Description: 2sed to store in"ormation about sa$esman !or5ing in t#e company% Column Name Data 'ype Si:e SOno Iarc#ar2 ; SOname Iarc#ar2 20 Address1 Iarc#ar2 @0 Address2 Iarc#ar2 @0 city Iarc#ar2 20 /incode umber A State Iarc#ar2 20 Sa$Oamt umber A(2 TgtOtoOget umber ;(2 JtdOsa$es umber ;(2 remar5s Iarc#ar2 ;0 A5 'able Name: Client9master Client9no C001 C002 C00@ C00< C008 C00; Name *)an Iandana /ramada Basu .a)i .u5mani City Bombay Madras Bombay Bombay De$#i Bombay %incode <0008< :A0001 <0008: <0008; 100001 <00080 State Ma#aras#tra Tami$ adu Ma#aras#tra Ma#aras#tra Ma#aras#tra )al9due 18000 0 8000 0 2000 0

)5 'able Name: %roduct9master /roductO o /001 /002 /00@ /00< /008 /00; /00: Description H$oppies Monitor Mouse H$oppies 6eyboards Cd Dri)e 1%<< Dri)e /O percent 8 ; 8 8 2 2%8 < 2O Measure /iece /iece /iece /iece /iece /iece /iece BtyOonO #and 100 10 20 100 10 10 10 .eorderO $)$ 20 @ 8 20 @ @ @ se$$O price 828 12000 1080 828 @180 8280 A<00 CostO price 800 112A0 1000 800 @080 8100 A000

C5 'able Name: Salesman9master SOno S001 SOname 6iran City Bombay /in <0000 2 State Ma#aras#t ar Sa$O Amt @000 TgtO to get 100 JtdO Sa$es 80 remar5s Eood

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

S002 S00@ S00<

Manis# .a)i As#is#

Bombay Bombay Bombay

<0000 1 <000@ 2 <000< <

Ma#aras#t a Ma#aras#t a Ma#aras#t a

@000 @000 @800

200 200 200

100 100 180

Eood Eood Eood

So$)e t#e "o$$o!ing &ueries using t#e database gi)en abo)e% A5 Retrieving records from table; 12@<8;Hind out t#e names o" a$$ c$ients% .etrie)e t#e entire content o" t#e c$ientOmaster tab$e% .etrie)e t#e $ist o" names and t#e cities o" a$$ t#e c$ients List t#e )arious products a)ai$ab$e "rom t#e productOmaster tab$e% List a$$ t#e c$ients !#o are $ocated in Bombay% Hind t#e names o" t#e sa$esman !#o #a)e a sa$ary e&ua$ to .s% @000

)5 &pdating records in a table; 12@<C#ange t#e city o" c$ientOno1C0021 to QBombay1% C#ange t#e ba$Odue o" c$ientOno1C0011 to .s%1000 C#ange t#e cost price o" H$oppies to .s% 980%00 C#ange t#e city o" t#e sa$esman to Mumbai%

C5 Deleting records in a table: 1- De$ete a$$ sa$esman "rom t#e sa$esmaneOmaster !#ose sa$aries are e&ua$ to .s% @800% 2- De$ete a$$ products "rom productOmaster !#ere t#e &uantity on #and is e&ua$ to 100% @- De$ete "rom c$ientOmaster !#ere t#e co$umn state #o$ds t#e )a$ue QTami$ adu1% E5 Altering t,e table structure: 1- Add a co$umn ca$$ed Qte$ep#one1 o" datatype Qnumber1 and si'eR10 to t#e c$ientOmaster tab$e% 2- C#ange t#e si'e o" se$$Oprice co$umn in productOmaster to 10(2% #5 Deleting t,e table structure along .it, data: 1- Destroy t#e tab$e c$ientOmaster a$ong !it# its data% (5 Renaming t,e table: 1- C#ange t#e name o" t#e sa$esmanOmaster tab$e to smanOmast% C M%&'A'I N N 'A)"E DA'A

one o" t#e tec#ni&ues used ti$$ no! a$$o!s disp$ays o" some data "rom a tab$e a"ter some arit#metic #as been done !it# it%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Arit#metic and $ogica$ operators gi)e a ne! dimension to SBL sentences% Arit,metic perators:

Crac$e a$$o!s arit#metic operator to be used !#i$e )ie!ing records "rom a tab$e or !#i$e per"orming Data Manipu$ation operations suc# as *nsert( 2pdate and De$ete% ? 3 / Addition Subtraction Di)ision F Mu$tip$ication FF E+ponentiation , - Enc$osed operation

Hor e+amp$e: .etrie)e t#e content o" t#e co$umn pOno( description and compute 8S o" t#e )a$ues contained in t#e co$umn se$$Oprice "or eac# ro! "rom t#e tab$e productOmaster% S&$KSE"EC' pOno( description( se$$OpriceF0%08 #R M productOmasterG

Renaming Columns used .it, E4pression "ists: =#en disp$aying t#e resu$t o" a &uery( SBL F/L2S norma$$y uses t#e se$ected co$umnTs name as t#e co$umn #eading% T#ese co$umn names may #o!e)er be s#ort and crypticG t#ey can be c#anged "or better understanding o" t#e &uery resu$t by entering an a$ias( or substitute name( a"ter t#e co$umn name in t#e se$ect c$ause% S&$KSE"EC' co$umnname resu$tOco$umnname( co$umnname resu$tOco$umnname #R M tab$e name Hor e+amp$e: .etrie)e t#e content o" t#e co$umn pOno( description and compute 8S o" t#e )a$ues contained in t#e co$umn se$$Oprice "or eac# ro! "rom t#e tab$e productOmaster% .ename se$$Oprice F 0%08 as Increase; S&$KSE"EC' pOno( description( se$$OpriceF0%08 *ncrease #R M productOmasterG "ogical perators:

Logica$ operators t#at can be used in SBL sentence are: <; AND operator: T#e Crac$e engine !i$$ process a$$ ro!s in a tab$e and disp$ay t#e resu$t on$y !#en a$$ o" t#e conditions
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

speci"ied using t#e A D operator are satis"ied% s&$ =SE"EC' co$umn $ist #R M tab$ename /*ERE co$umnname AND co$umnnameG S&$KSE"EC' pOno( desc( pOpercent #R M productOmaster /*ERE pOpercentKR10 AND pOpercentMR20G >; R operator:

T#e Crac$e engine !i$$ process a$$ ro!s in a tab$e and disp$ay t#e resu$t on$y !#en any o" t#e conditions speci"ied using t#e C. operators are satis"ied% s&$ =SE"EC' co$umn $ist #R M tab$ename /*ERE co$umnname #R M c$ientOmaster /*ERE ,pincodeR<00128 ?; N ' operator: T#e Crac$e engine !i$$ process a$$ ro!s in a tab$e and disp$ay t#e resu$t on$y !#en none o" t#e conditions speci"ied using t#e CT operator are satis"ied% S&$K SE"EC' cOno( name( address( pincode #R M c$ientOmaster /*ERE N ' ,cityR1Bombay1 or cityR1De$#i1-G Range Searc,ing: *n order to se$ect data t#at is !it#in a range o" )a$ues( t#e )E'/EEN operator is used% T#is operator a$$o!s t#e se$ection o" ro!s t#at contain )a$ues !it#in a speci"ied $o!er and upper $imit% s&$ =SE"EC' co$umn $ist "rom tab$ename /*ERE co$umn )E'/EEN min O)a$ue AND ma+O)a$ueG
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

R co$umnnameG

s&$ =SE"EC' cOno( name( address( pincode R pincodeR<0012;-G

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

s&$ =SE"EC' cOno( name( address( pincode #R M c$ientOmaster /*ERE ba$Odue )E'/EEN 100 AND 800G Note: %BET=EE is an inc$usi)e operator i%e% i" eit#er t#e min )a$ue or t#e ma+ )a$ue is "ound( as !e$$ as any in bet!een( t#e ro! is returned% @; N ' )E'/EEN .o!s not #a)ing )a$ue in t#e range speci"ied( and a$so not #a)ing )a$ue e&ua$G to min or t#e ma+ )a$ue is returned% s&$ =SE"EC' co$umn $ist "rom tab$ename /*ERE co$umn N ' )E'/EEN min O)a$ue AND ma+O)a$ueG s&$ =SE"EC' cOno( name( address( pincode #R M c$ientOmaster /*ERE ba$Odue N ' )E'/EEN 100 AND 800G %attern Matc,ing: <; "IKE A$$o!s comparison o" one string )a$ue !it# anot#er string )a$ue( !#ic# is not identica$% T#is is ac#ie)ed by using !i$dcard c#aracters% T!o !i$dcard c#aracters t#at are a)ai$ab$e are: T#e percent sign 3A5 t#at matc#es any string% T#e 2nderscore 3 9 5 t#at matc#es any sing$e c#aracter% s&$ KSE"EC' co$umn $ist #R M tab$ename /*ERE co$umn "IKE TpatternTG C. /*ERE column N ' "IKEB patternBHor e+amp$e:
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

.etrie)e a$$ in"ormation about supp$iers !#ose name begin !it# t#e $etter QDa1 "ro supp$ierOmaster% s&$ KSE"EC' $ #R M supp$ierOmaster /*ERE sOname "IKE CDaS1G >; IN T#is operator can be used to se$ect ro!s t#at matc# one o" t#e )a$ues inc$uded in t#e $ist% s&$KSE"EC' co$umn$ist #R M tab$ename /*ERE co$umn$ist IN 3$ist o" )a$ues-G Hor e+amp$e: .etrie)e t#e detai$s "rom supp$ier tab$e !#ere supp$ier name is eit#er Aman or Iima$ or ADay% s&$KSE"EC' sOno( name( city( address( pincode #R M supp$ierOmaster /*ERE name IN ,QAman1( QIima$1( Q ADay1 -G ?; N ' IN T#e N ' IN predicate is t#e opposite o" t#e * not matc# a$$ o" t#e )a$ues in t#e $ist% predicate% T#is !i$$ se$ect a$$ t#e ro!s !#ere )a$ues do

s&$KSE"EC' co$umn$ist #R M tab$ename /*ERE co$umn$ist N ' IN 3$ist o" )a$ues-G @; IS N&"" T#is operator is used to compare t#e )a$ue in t#e co$umn !it# s&$ KSE"EC' co$umn $ist #R M tab$ename /*ERE co$umn is N&""C. /*ERE co$umn is not N&""RAC"E #&NC'I NS: Crac$e "unctions ser)e t#e purpose o" manipu$ating data items and returning resu$t% Hunctions are a$so capab$e o" accepting user3supp$ied )ariab$es or constants and operating on t#em% Suc# )ariab$es or constants are ca$$ed as argument% Any number o" arguments can be passed to a "unction in t#e "o$$o!ing "ormat: #unction9name 3argument<D argument>D E5;
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

2LL and return t#e ro! according$y%

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Crac$e "unctions can be c$ubbed toget#er depending upon !#et#er t#ey operate on a sing$e ro! or a group o" ro!s retri)ed "rom a tab$e% According$y( "unctions can be c$assi"ied as "o$$o!s: (roup #unctions 3Aggregate #unction5: Hunctions t#at act on a set o" )a$ues are ca$$ed as group "unctions% Hor e+amp$e( S2M( is a "unction !#ic# ca$cu$ates t#e tota$ o" a set o" numbers% A group "unction returns a sing$e resu$t ro! a group o" &ueried ro!s% Scalar #unction 3Single Ro. #unction5: Hunctions t#at act on on$y one )a$ue at a time are ca$$ed as sca$ar "unctions% Hor e+amp$e( LE ET>( is a "unction( !#ic# ca$cu$ates t#e $engt# o" one particu$ar string )a$ue% A sing$e ro! "unction returns one resu$t "or e)ery ro! o" a &ueried tab$e or )ie!% Sing$e ro! "unction can be "urt#er grouped toget#er by t#e data type o" t#eir arguments and return )a$ues% Hor e+amp$e( LE ET>( re$ates to t#e string Data type% Hunctions can be c$assi"ied corresponding to di""erent data types as: String "unctions umeric "unctions Con)ersion "unctions Date "unctions : =or5 "or String Data type : =or5 "or umber Data type : =or5 "or Con)ersion o" one type to anot#er% : =or5 "or Date Data type

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Aggregate #unctions: A+( Synta+ /urpose E+amp$e Cutput Synta+ /urpose E+amp$e Cutput Synta+ /urpose E+amp$e Cutput Synta+ /urpose E+amp$e Cutput MA6 S&M Synta+ /urpose E+amp$e Synta+ /urpose E+amp$e Cutput AIE,LD*ST* CT7ALLNn.eturn a)erage )a$ue o" n ignoring nu$$ )a$ues% Se$ect AIE,se$$Oprice- UA)erageV "rom pOmasterG A)erage 2012%@;8< M* ,LD*ST* CT7ALLNe+pr.eturn minimum )a$ue o" Qe+pr1% Se$ect M* ,ba$Odue- UMinOba$V "rom cOmasterG MinOba$ 0 M* ,LD*ST* CT7ALLNe+pr.eturn t#e number o" ro!s =>E.E Qe+pr1 is not nu$$ % Se$ect CC2 T,pOno- U/roductsV "rom /OmasterG /roducts 9 CC2 T,F.eturn t#e number o" ro!s in t#e tab$e( inc$uding dup$icates and t#ose !it# nu$$s%% Se$ect CC2 T,F- UTota$V "rom COmasterG Tota$ 9 MAW,LD*ST* CT7ALLNe+pr.eturn ma+imum )a$ue o" Qe+pr1% Se$ect MAW,ba$Odue- UMa+imumV "rom cOmasterG S2M,LD*ST* CT7ALLNn.eturn Sum o" )a$ues o" Qn1% Se$ect S2M,ba$Odue- UBa$anceV "rom cOmasterG Ba$ance 22000

MIN

C &N'

C &N'3$5

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Numeric #unctions:
A)S Synta+ /urpose E+amp$e Cutput ABS,n.eturn t#e abso$ute )a$ues o" Qn1% Se$ect ABS,318- UAbso$uteV "rom dua$G Abso$ute 18 /C=E.,m(n.eturns m raised to nt# po!er% must be an integer( e$se an error is returned% Se$ect /C=E.,@(2- U.aisedV "rom dua$G .aised 9 ABS,nL(MN.eturns Qn1 rounded to Qm1 p$aces rig#t t#e decima$ point% *" Qm1 is omitted Qn1 is rounded to 0 p$aces% Qm1 can be negati)e to round o"" digit $e"t o" t#e decima$ point Qm1 must be an integer% Se$ect .C2 D,18%19(1- U.oundV "rom dua$G .ound 18%2 SB.T,n.eturns s&uare root o" Qn1% i" nM0( 2LL% SB.T returns a rea$ resu$t% Se$ect SB.T,28- US&uare rootV "rom dua$G S&uare root 8

% /ER

Synta+ /urpose E+amp$e Cutput

R &ND

Synta+ /urpose E+amp$e Cutput

S!R'

Synta+ /urpose E+amp$e Cutput

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

String #unctions:
" /ER Synta+ /urpose E+amp$e Cutput LC=E.,c#ar.eturn c#ar( !it# a$$ $etters in $o!ercase% Se$ect LC=E.,QWJX1- ULo!erV "rom dua$G Lo!er +y' Synta+ * *TCA/,c#ar/urpose .eturn ST.* E !it# "irst $etter in upper case% E+amp$e Se$ect * *TCA/,QCCM/ DE/T1- UTit$e CaseV "rom dua$G Cutput Tit$e Case Comp Dept Synta+ /urpose E+amp$e Cutput

INI'CA%

&%%ER

2//E.,c#ar.eturn c#ar( !it# a$$ $etters in uppercase% Se$ect 2//E.,Q+y'1- U2pperV "rom dua$G 2pper WJX S&)S'R Synta+ 2//E.,c#ar( ML(nN/urpose .eturn a portion o" c#ar( beginning at c#aracter Qm1 e+ceeding up to Qn1 c#aracters% *" Qn1 is omitted( resu$t is returned up to t#e end c#ar% T#e "irst position o" c#ar is 1% E+amp$e Se$ect S2BST.,QSEC2.E1(@(<- USubstringV "rom dua$G Cutput Substring C2.E "EN('* Synta+ /urpose E+amp$e Cutput "'RIM LE ET>,c#ar.eturn t#e $engt# o" c#aracter% Se$ect LE ET>,Q+y'1- ULengt#V "rom dua$G Lengt# @ Synta+ LT.*M,c#arL(SetN/urpose .eturn c#aracters "rom t#e $e"t o" c#ar !it# initia$% E+amp$e Se$ect LT.*M,QCo$$ege1(1C1- ULe"tV "rom dua$G Cutput Le"t o$$ege Synta+ .T.*M,c#arL(SetN/urpose R'RIM .eturn c#ar( !it# "ina$ c#aracters remo)ed a"ter t#e $ast c#aracter not * t#e set% Qset1 is optiona$( it de"au$ts to spaces% E+amp$e Se$ect .T.*M,QCo$$ege1(1e1- U.ig#tV "rom dua$G
A dreamMAKERS *nitiati)e

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Cutput "%AD Synta+ /urpose

.ig#t Co$$eg

R%AD

L/AD,c#ar1(n(L(c#ar2N.eturn Qc#ar11( $e"t padded to $engt# Qn1 !it# t#e se&uence o" c#aracters in Qc#ar21( Qc#ar2( de"au$ts to b$an5s% E+amp$e Se$ect L/AD,Q/age 11(10(1F1- ULpadV "rom dua$G Cutput Lpad FFFF/age 1 Synta+ ./AD,c#ar1(n(L(c#ar2N/urpose .eturn Qc#ar11( rig#t3 padded to $engt# Qn1 !it# t#e c#aracters in Qc#ar21( rep$icated as many times as necessary% *" Qc#ar21 is omitted( rig#t3pad is !it# b$an5s% E+amp$e Se$ect ./AD,Qpage1(10(1+1- U.padV "rom dua$G Cutput .pad /age++++++

Conversion #unctions: ' 9N&M)ER Synta+ /urpose E+amp$e TCO 2MBE.,c#arCon)erts Qc#ar1 ( a c#aracter )a$ue containing a number to a )a$ue o" number datatype% 2pdate /Omaster set se$$OpriceR se$$Oprice ? TCO 2MBE.,S2BST.,QY1001(2(@--G >ere t#e )a$ue 100 !i$$ be added to e)ery products se$$ing price in t#e productOmaster tab$e% TCOC>A.,nL("mtNCon)erts a )a$ue o" number data type to a )a$ue o" c#ar data type( using t#e optiona$ "ormat string% *t accepts a number ,nand a numeric "ormat ,"mt- in !#ic# t#e number #as to appear% *" Q"mt1 is omitted( Qn1 is con)erted to a c#ar )a$ue e+act$y $ong enoug# to #o$d signi"icant digits% Se$ect TCOC>A.,1:1<8(1Y099(9991-Vc#arV "rom dua$G C#ar Y01:(1<8 TCOC>A.,dateL("mtNCon)erts a )a$ue o" DATE data type to a )a$ue o" c#ar data type( using t#e optiona$ "ormat string% *t accepts a date ,date-( as !e$$ as "ormat ,"mt- in !#ic# t#e date #as to appear% Q"mt1 must be a date "ormat%% *" Q"mt1 is omitted( Qdate1 is con)erted to a c#ar )a$ue in t#e de"au$t date "ormat( i%e% UDD3MC 3JJV% Se$ect TCOC>A.,CODATE(1Mont# DD( JJJJUHormatV "rom sOorder !#ere oOnoR1o<28<11G Hormat
A dreamMAKERS *nitiati)e

' 9C*AR

Synta+ /urpose

E+amp$e Cutput ' 9C*AR Synta+ /urpose

E+amp$e Cutput

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Zanuary 2;( 2000;

Date Conversion #unctions:


' 9DA'E Synta+ /urpose Synta+ /urpose E+amp$e Cutput "AS'9DA2 Synta+ /urpose E+amp$e Cutput M N'*S9)E'/EEN Synta+ /urpose E+amp$e Cutput NE6'9DA2 Synta+ /urpose E+amp$e Cutput TCODATE,c#ar L("mtNCon)erts a c#aracter "ie$d to a date "ie$d% ADDOMC T>S,D( .eturns date a"ter adding t#e number o" mont#s speci"ied !it# t#e "unction Se$ect ADDOMC T>S,SJSDATE( <"rom dua$G ADDOMC T>S 0<3A2E30; LASTODAJ,d.eturns t#e $ast date o" t#e mont# speci"ied !it# t#e "unction% Se$ect SJSDATE(LASTODAJ,SJSDATE-VLastV "rom dua$G SJSDATE Last 0<3A2E30; @13A2E30; MC T>SOBET=EE ,d1(d2.eturns number o" mont#s bet!een d1 and d2% Se$ect MC T>SOBET=EE ,10<3A2E30;1( Q0<3Z2L30;1 -VMont#V "rom dua$G Mont# 1 EWTODAJ,date(c#ar.eturns t#e date o" t#e "irst !ee5day named by Qc#ar1 t#at is a"ter t#e date named by Qdate1% QC#ar1 must be a day o" t#e !ee5% se$ect EWTODAJ,10<3"eb30;1( QHriday1U e+t dayV "rom dua$G e+t day 0;3"eb30;

ADD9M N'*S

',e

racle 'able CD&A"8:

Dua$ is a sma$$ Crac$e !or5tab$e( !#ic# consists o" on$y one ro! and and one co$umn( and contains t#e )a$ue + in t#at co$umn% Besides arit#metic ca$cu$ation( it a$so supports date retrie)a$ and it1s "ormatting%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

=#en an arit#metic e+ercise is to be per"ormed suc# as 2F2 or </@ etc%( t#ere rea$$y is no tab$e being re"erencedG on$y numeric $itera$s are being used% To "aci$itate suc# ca$cu$ation )ia a SELECT( Crac$e pro)ides a dummy tab$e ca$$ed D2AL( against !#ic# SELECT statements t#at are re&uired to manipu$ate numeric $itera$s can be "ired( and output obtained% S&$KSE"EC' 2F2 #R M D2ALG Cutput: 2F2 OOOOOOOOOO < S2SDA'E: Sysdate is a pseudo co$umn t#at contains t#e current date and time% *t re&uires no arguments !#en se$ected "rom t#e tab$e D2AL and returns t#e current date% S&$KSE"EC' sysdate #R M D2ALG Cutput: Sysdate OOOOOOOOOOOO 0;3Dun30; !ueries on computation on table data: 1- Hind t#e name o" a$$ c$ients #a)ing Qa Q as t#e second $etter in t#eir names 2- Hind out t#e c$ients !#o stay in a city !#ose second $etter is Qa1% @- Hind t#e $ist o" a$$ c$ients !#o stay in QBombay1 or QDe$#i1% <- /rint t#e $ist o" c$ients !#ose ba$Odue is greater t#an )a$ue 10000% 8- /rint t#e in"ormation "rom sa$esOorder tab$e "or orders p$aced in t#e mont# o" Zanuary% ;- Disp$ay t#e order in"ormation "or c$ientOno Qc0011 and Qc0021% :- Hind products !#ose se$$ing price is greater t#an 2000 and $ess t#an or e&ua$ to 8000% A- Hind products !#ose se$$ing price is more t#an 1800% ca$cu$ate a ne! se$$ing price as( origina$ se$$ing price F %18% rename t#e ne! co$umn in t#e abo)e &uery as ne!Oprice%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

9- List t#e names( city and state o" c$ients !#o are not in t#e state o" QMa#aras#tra1% 10- Count t#e tota$ number o" orders% 11- Ca$cu$ate t#e a)erage price o" a$$ products% 12- Determine t#e ma+imum and minimum product prices% .ename t#e output as ma+Oprice and minOprice respecti)e$y% 1@- Count t#e number o" products #a)ing price greater t#an or e&ua$ to 1800% 1<- Hind a$$ t#e products !#ose &tyOonO#and is $ess t#an reorder $e)e$% !ueries on Date manipulation: 1- Disp$ay t#e order number and day on !#ic# c$ients p$aced t#eir order% 2- Disp$ay t#e mont# ,in a$p#abets- and date !#en t#e order must be de$i)ered% @- Disp$ay t#e orderOdate in t#e "ormat QDD3MC T>3JJ1% E%E% 123August30;% <- Hind t#e date( 18 days a"ter today1s date% 8- Hind t#e number o" days e$apsed bet!een today1s date and de$i)ery date o" t#e orders p$aced by t#e c$ients% DA'A C NS'RAIN'S A$$ business app$ication o" t#e !or$d run on business data gat#ered( stored and ana$y'ed% Business managers determine a set o" ru$es t#at must be app$ied to t#e data being stored to ensure its integrity% Hro instance( no emp$oyee in t#e sa$es department can #a)e a sa$ary o" $ess t#an .s% 1000/3% Suc# $imitation #a)e to be en"orced on t#e data( and on$y t#at data !#ic# satis"ies t#e condition set !i$$ actua$$y be stored "or ana$ysis% Crac$e permits data constraints to be attac#ed to tab$e co$umns )ia SBL synta+ t#at !i$$ c#ec5 data "ro integrity% Cnce data constraints are part o" a tab$e co$umn construction( t#e orac$e engine c#ec5s t#e data being entered into a tab$e co$umn against t#e data constraints% *" t#e data passes t#is c#ec5( it is stored in t#e tab$e( e$se t#e data is reDected% Crac$e a$$o!s programmers to de"ine constraints at: Co$umn Le)e$ Tab$e Le)e$ Column "evel Constraints:
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

*" data constraints are de"ined a$ong !it# t#e co$umn de"inition !#en creating or a$tering a tab$e structure( t#ey are column level constraints% Co$umn $e)e$ constraints are app$ied to t#e current co$umn% T#e current co$umn is t#e co$umn t#at immediate$y precedes t#e constraints i%e% t#ey are $oca$ to a speci"ic co$umn% A co$umn $e)e$ constraint cannot be app$ied i" t#e data constraints spans across mu$tip$e co$umns in a tab$e% 'able "evel Constraints: *" data constraints are de"ined a"ter de"ining a$$ t#e tab$e co$umns !#en creating or a$tering a tab$e structure( it is a tab$e $e)e$ constraint% Tab$e $e)e$ constraint must be app$ied i" t#e data constraint spans across mu$tip$e co$umns in a tab$e% IN'E(RI'2 C NS'RAIN' N&"" constraints: T#ere may be records in a tab$e t#at do not #a)e )a$ues "ro e)ery "ie$d( eit#er because t#e in"ormation is not a)ai$ab$e at t#e time o" data entry or because t#e "ie$d is not app$icab$e in e)ery case% A 2LL )a$ue is not e&ui)a$ent to a )a$ue o" 'ero i" t#e data type is number and spaces i" t#e

data type is c#aracter% A 2LL )a$ue !i$$ e)a$uate to 2LL in any e+pression e%g% 2LL mu$tip$ied by 10 is 2LL 2LL )a$ue can be inserted into co$umns o" any data type% 2LL )a$ue( orac$e ignores t#e 2 *B2E( HC.E*E 6EJ( C>EC6

*" t#e co$umn #as a

constraints t#at may be attac#ed to t#e co$umn% N ' N&"" constraint defined at t,e column level: =#en a co$umn is de"ined as not 2LL( t#en t#at co$umn becomes a mandatory co$umn% *t imp$ies t#at

a )a$ue must be entered into t#e co$umn i" t#e record is to be accepted "or storage in t#e tab$e% Synta4: Co$umnname datatype,si'e- N ' N&""

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

SFl= Create table c$ientOmaster , cOno )arc#ar2,8- N ' N&""( name )arc#ar2,10- N ' N&""D address )arc#ar2,20- N ' N&"" -G T#e CT 2LL constraint can on$y be app$ied at co$umn $e)e$% &NI!&E constraints: T#e purpose o" a uni&ue 5ey is to ensure t#at in"ormation in t#e co$umns is uni&ue( i%e% a )a$ue entered in co$umn de"ined in t#e uni&ue constraints must not be repeated across t#e co$umns% A tab$e may #a)e many uni&ue 5eys% &NI!&E constraint defined at t,e column level: Synta4: Co$umnname datatype,si'e- &NI!&E SFl= Create table c$ientOmaster , cOno )arc#ar2,8- &NI!&ED name )arc#ar2,10-( pincode &NI!&E -G &NI!&E constraint defined at t,e 'able level: SFl= Create table c$ientOmaster , cOno )arc#ar2,8-( name )arc#ar2,10-( address )arc#ar2,20&NI!&E ,cOno( pincode--G DE#A&"' constraint: At t#e time o" tab$e creation a Qde"au$t )a$ue1 can be assigned to a co$umn% =#en t#e user is $oading a record !it# )a$ues and $ea)es t#is co$umn empty( t#e orac$e engine !i$$ automatica$$y $oad t#is co$umn !it# t#e de"au$t )a$ue speci"ied% T#e datatype o" de"au$t )a$ue s#ou$d matc# t#e data type o" t#e co$umn% Synta4: Co$umnname data type,si'e- DE#A&"' ,)a$ueC2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Create a sa$esOorder tab$e !#ere t#e de"au$t )a$ue "or t#e co$umn de$yOtype is t#e c#aracter( upper case QH1 ,Hu$$-% S&$KCRE'A'E 'A)"E sa$esOorder , oOno )arc#ar2,;-( oOdate date( cOno )arc#ar2,;de$yOtype c#ar,1- DE#A&"' C#8D bOyn c#ar,1--G %RIMAR2 KE2 constraint: A primary 5ey is one or more co$umns in a tab$e used to uni&ue$y identi"y eac# ro! in t#e tab$e% A primary 5ey co$umn in a tab$e #as specia$ attributes: *t de"ines t#e co$umn as a mandatory co$umn i%e% t#e co$umn cannot be $e"t b$an5% T#e N ' N&"" attribute is acti)e% T#e data #e$d across t#e co$umn must be 2 *B2E% %RIMAR2 KE2 constraint defined at t,e column level: S&$KC.EATE TABLE sa$esOorderOdetai$s , detorderOno )arc#ar2,8- %RIMAR2 KE2D /Ono )arc#ar2,8- %RIMAR2 KE2D /Orate number ,A(2-( &tyOordered number,;-G %RIMAR2 KE2 constraint defined at t,e table level: S&$KC.EATE TABLE sa$esOorderOdetai$s , detorderOno )arc#ar2,8-( /Ono )arc#ar2,8-( /Orate number ,A(2-( &tyOordered number,;%RIMAR2 KE2 ,detorderOno( pOno-G C*ECK constraints Business ru$e )a$idations can be app$ied to a tab$e co$umn by using C>EC6 constraint% *t must be speci"ied as a $ogica$ e+pression t#at e)a$uates eit#er to T.2E or HALSE% SFl= Create table c$ientOmaster , cOno )arc#ar2,8- C*ECK ,cOno $i5e QCS1-( name )arc#ar2,10- C*ECK ,nameRupper,name--( address )arc#ar2,20- -G Note: A C>EC6 constraint ta5es $onger to e+ecute as compared to ot#er constraints t#us( C>EC6 constraints must be a)oided i" t#e constraint can be de"ined using t#e ot u$$( /rimary 5ey( Horeign 5ey constraint%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

A C>EC6 integrity constraint re&uires t#at a condition be true or un5no!n "or t#e ro! to be processed% T#e condition must be a Boo$ean e+pression t#at can be e)a$uated using t#e a )a$ues in t#e ro! being inserted or updated% T#e condition cannot contain sub &ueries or se&uences% # REI(N KE2 constraint: Horeign 5ey represent re$ations#ips bet!een tab$es% A "oreign 5ey is tab$e !#ose )a$ues are deri)ed "rom t#e primary 5ey or uni&ue 5ey o" some ot#er tab$e% T#e tab$e in !#ic# t#e "oreign 5ey is de"ined is ca$$ed a foreign table or Detail table; T#e tab$e t#at de"ines t#e primary or uni&ue 5ey and is re"erenced by t#e "oreign 5ey is ca$$ed t#e %rimary table or Master table; T#e master tab$e can be re"erenced in t#e "oreign 5ey de"inition by using t#e .EHE.E CES ad)erb% *" t#e name o" t#e co$umn is not speci"ied( by de"au$t( orac$e re"erences t#e primary 5ey in master tab$e% T#e de"au$t be#a)ior o" t#e "oreign 5ey can be c#anged by using t#e C DELETE CASCADE C/T*C % =#en t#e t#is option is speci"ied in t#e "oreign 5ey de"inition( i" t#e user de$etes a record in t#e master tab$e( a$$ corresponding records in t#e detai$ tab$e a$ong !it# t#e record in t#e master tab$e !i$$ be de$eted% Synta4: Co$umnname datatype,si'e- RE#ERENCES tab$ename L,co$umnname-N LC DELETE CASCADEN S&$KC.EATE TABLE sa$esOorderOdetai$s , detorderOno )arc#ar2,8- RE#ERENCES sa$esOorder( /Ono )arc#ar2,8-( /Orate number ,A(2-( &tyOordered number,;%RIMAR2 KE2 ,detorderOno( pOno-G Note: .eDect an insert or update o" a )a$ue( i" a corresponding )a$ue does not current$y e+it in t#e master tab$e *" t#e C DELETE CASCADE option is set( a DELETE operation in t#e master tab$e !i$$ trigger t#e DELETE operation "ro corresponding records in t#e detai$ tab$e% .eDects a DELETE "or t#e Master tab$e i" corresponding records in t#e DETA*L tab$e e+it% Must re"erences a /.*MA.J 6EJ or 2 *B2E co$umns in primary tab$e% .e&uires t#at t#e HC.E*E 6EJ co$umns and t#e CC ST.A* T co$umns #a)e matc#ing data types% May re"erences t#e same tab$e named in t#e C.EATE TABLE statement%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e
4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

IN'E(RI'2 C NS'RAIN' IN A"'ER 'A)"E C MMAND E+amp$e: 1- Add a primary 5ey data constraint on t#e co$umn sOno be$onging to t#e tab$e sOmaster% S&$KA"'ER 'A)"E sOmaster ADD /.*MA.J 6EJ ,sOno-G 2- Add "oreign 5ey constraint on t#e co$umn detorderOno be$onging to a tab$e sOorderOdeati$s( !#ic# re"erences t#e tab$e sa$esOorder% Modi"y co$umn &tyOordered to inc$ude t#e CT 2LL constraint; SFl=A"'ER 'A)"E sOorderOdatais ADD HC.E*E 6EJ,detorderOno- .EHE.E CES SALESOC.DE. M DI#2 ,&tyOordered number,A- CT 2LL-G DR %%IN( IN'E(RI'2 C NS'RAIN'S E+amp$e : 1- Drop t#e /.*MA.J 6EJ constraint "rom supp$ierOmaster% S&$KA"'ER 'A)"E supp$ierOmaster DR % /.*MA.J 6EJG 2- Drop HC.E*E 6EJ constraint on co$umn pOno in tab$e sOorderOdeati$%

S&$K A"'ER 'A)"E sOorderOdetai$ DR % HC.E*E 6EJG S&) !&ERIES T#e SBL sub &uery is one o" t#e ad)anced &uery tec#ni&ues in SBL% T#is "eature $ets you use t#e resu$t o" one &uery as part o" anot#er &uery% T#is p$ays an important ro$e in SBL main$y due to "o$$o!ing reasons% SBL sub &uery is o"ten t#e most natura$ !ay to e+press a &uery( because it most c$ose$y para$$e$s t#e Eng$is#3$anguage description o" t#e &uery% Sub &ueries $ets you brea5 a &uery do!n into pieces and t#en put t#e pieces toget#er( #ence )ery simp$e to imp$ement% Some &ueries Dust can not be !ritten !it#out sub &ueries%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Sub&uery must be enc$osed in t#e parent#esis% Sub&ueries can be di)ided into t!o broad groups3 Sing$e ro! su&uery: T#is is sub&uery !#ic# returns on$y one )a$ue to t#e outer &uery% Mu$ti ro! su&uery: T#is is sub&uery !#ic# returns mu$tip$e )a$ues to t#e outer &uery% IN or N ' IN List t#e name( Dob and sa$ary o" peop$e in department 2o !#o #a)e t#e same Dob as peop$e in department @0% S&$=SE"EC' enmae( Dob( sa$ #R M EM/ /*ERE deptnoR20 and Zob IN 3SE"EC' Dob #R M EM/ .,ere deptnoR@0-AN2 or A"" *" a su&uery returns more t#an one ro! and t#e comparison ot#er t#an e&ua$ity is re&uired ,e%g% M(K( MRPetc- t#en t#e A J( ALL operators are used% *" t#e re$ation re&uired "or t#e $ist o" )a$ues returned by t#e inner &uery( t#en t#e A J operator is used% E+amp$e: Hind out t#e name( Dob and sa$ary o" peop$e in department 20 !#o earn more t#an any one in department @0% SFl=SE"EC' enameD GobD sal #R M emp /*ERE deptno7>H AND sal =AN2 3SE"EC' sal #R M emp /*ERE deptno7?H5*" t#e re$ation re&uired "or t#e outer co$umn in t#e =>E.E c$ause is suc# t#at it s#ou$d be T.2E "or a$$ t#e )a$ues in t#e $ist o" )a$ues returned by t#e inner &ueryG t#en t#e ALL operator is used% E+amp$e:

Hind out t#e name( Dob( sa$ary o" peop$e !#o earn sa$ary greater t#an a$$ t#e peop$e in department @0% S&$KSE"EC' ename( Dob( sa$ #R M emp /*ERE deptnoR20 A D sa$ =A"" ,SE"EC' sa$ #R M emp /*ERE deptnoR@0-G E6I'S:I T#e e+istence o" ro!s in t#e &uery may be used to &ua$i"y ro!s o" an outer &uery% T#e nested SELECT statement !i$$ be true i" one or more ro!s are "ound% *" no ro!s e+it in t#e nested SELECT statement( t#en t#at portion o" t#e =>E.E c$ause !i$$ be "a$se%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

E+amp$e: Hind a$$ t#e departments t#at #a)e emp$oyees !#o e+ist in t#em% S&$=SE"EC' deptno( dname( $oc #R M dept /*ERE E6I'S 3SE"EC' deptno #R M emp /*ERE deptnoR emp%deptno5Sub Fueries returning multiple columns:I *nner &ueries can return more t#an one co$umns% Cn$y one care s#ou$d be ta5en to !rite t#e &uery in suc# a !ay t#at t#e order and t#e type o" t#e co$umn se$ected by t#e inner &uery% E+amp$e: Hind out !#o are t#e #ig#est paid emp$oyees in eac# department% S&$KSE"EC' deptno( ename( sa$ from emp /*ERE ,deptno( sa$IN ,SE"EC' deptno( ma+ ,sa$- #R M emp (R &% )2 deptno-G Correlated subFueries Consider t#e &uery !#ere !e #a)e to "ind out t#e emp$oyees !#o earn more t#an t#e a)erage sa$ary in t#eir o!n department% S&$KSE"EC' deptno( ename( sa$ #R M emp /*ERE Sa$K 3SE"EC' a)g ,sa$- #R M emp /*ERE deptnoRdeptno-G A corre$ated su&uery re"ers to a co$umn se$ected by t#e main &uery% *" a &uery per"orms a se$ect "rom t#e same tab$e as t#e main &uery t#e main &uery must de"ine an a$ias "or t#e tab$e name and t#e sub&uery must use t#e a$ias to re"er to t#e tab$e name and t#e su&uery must use t#e a$ias to re"er t#e co$umn )a$ue in t#e main &uery1s candidate ro!s% >AI* E c$ause can a$so be used in corre$ated su&uery% Solve t,e follo.ing Fueries using sub Fueries:I 1- Hind t#e productOno and description o" non mo)ing products i%e% product not being so$d% 2- Hind t#e customer name( address1( address2( city and pincode "or t#e c$ient !#o #as p$aced order no QC190011% @- Hind t#e c$ient names !#o #a)e p$aced orders be"ore t#e mont# o" may19;% <- Hind out i" t#e product Q"$oppies1 #as been ordered by any c$ient and print t#e c$ientOno( name to !#om it !as so$d%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

8- Hind t#e names o" c$ients !#o #a)e p$aced orders !ort# .s% 10000 or more% J ININ( 'A)"ES *n a rea$ $i"e situation( many times one needs to use &ueries !#ic# re&uest data "rom t!o or more tab$es in t#e database% J INS T#e process o" "orming ro!s "rom t!o or more tab$es by comparing t#e contents o" re$ated co$umn is ca$$ed Doining tab$es% T#e resu$ting tab$e ,containing data "rom bot# t#e origina$ tab$e- is ca$$ed a Doin bet!een t#e tab$es% Zoins are "oundation o" mu$ti3tab$e &uery processing in SBL% Since SBL #and$es mu$ti3tab$e &ueries by matc#ing co$umns( it uses t#e SELECT command "or a searc# condition t#at speci"ies a co$umn matc#% SFl=SE"EC' columns #R M table<D table>DE /*ERE logical e4press T#e !#ere c$ause speci"ies #o! to Doin or merge t#e tab$es toget#er as !e$$ as t#e searc# criteria i" any% Co$umns "rom tab$es may be named in SELECT c$ause% Co$umns !#ic# #a)e t#e same name in mu$tip$e ta$e named in t#e "rom c$ause must be uni&ue$y identi"ied by speci"ying tab$ename%co$umn name% Tab$ename%F is s#ort cut to speci"y a$$ t#e co$umns in t#e tab$e% More t#an one pair o" co$umns may be used to speci"y t#e Doin condition bet!een t!o tab$es% &sing aliases =#en using a Doin( it is good idea to identi"y a$$ co$umns by using t#eir tab$e names% >o!e)er( typing $ong tab$e names can be di""icu$t sometimes% So( to o)ercome t#is prob$em one can de"ine s#ort name a$iases "or tab$es% SFl= SE"EC' t<;col<D t<;col>D t>;col? #R M table t<D table t> /*ERE t<;col<7 t>;col <>ere t1 and t2 are used as a$iases "or tab$e 1 and tab$e 2 respecti)e$y% EFuiIGoins
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

A Doin t#at is "ormed as a resu$t o" an e+act matc# bet!een t!o co$umns is ca$$ed an e&ui3Doin or a simp$e Doin% Consider &uery in !#ic# !e !ant to 5no!n t#e name o" t#e emp$oyee( #is department and its $ocation% SFl = SE"EC' enameD deptnoD loc #R M empD dept /*ERE emp;deptno 7 dept;deptnoCartesian Goin: *" t#e c$ause is omitted( a Cartesian Doin is per"ormed% A Cartesian product matc#es e)ery ro! o" a one tab$e to e)ery ro! o" t#e ot#er tab$e% SFl=SE"EC' ename( $oc #R M EM/( DE/T /*ERE DobR1CLE.61NonIeFui Goin:I T#e Doin !#ic# uses comparison operation ot#er t#an QR1 !#i$e de"ining t#eir Doining criteria are ca$$ed non3e&ui Doins% Since t#is Doin can resu$t in $arge number o" ro!s( it is ad)isab$e to ma5e a non3e&ui Doin in combination !it# a se$ection criteria to reduce t#e ro!s to a manageab$e range% SelfIGoin:I A se$" Doin is used to matc# and retrie)e ro!s t#at #a)e matc#ing )a$ue in di""erent co$umns o" t#e same tab$e% Consider t#at you !ant to 5no!n t#e number( name and Dob o" eac# emp$oyee( a$ong !it# t#e number( name and Dob o" t#e emp$oyee1s manager t#en !e can !rite $i5e t#is%% S&$ K SE"EC' !or5er%empno( !or5er%ename( !or5er%Dob( manager%empno( manager%ename( manager%Dob #R M emp !or5er( emp manager /*ERE !or5er%empnoRmanager%empnoG
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

A tab$e can be Doined to itse$" as i" it !ere t!o tab$es% As !it# any ot#er Doin( t#e Doin is on co$umns t#at contain t#e same type o" in"ormation% T#e tab$e must be gi)en s a$ias to sync#roni'e !#ic# co$umns are coming "rom !#ic# tab$es% uter Goin:I To inc$ude ro!s in a Doined resu$t e)en !#en t#ey #a)e no matc# in a Doined tab$e( t#e outer Doin is used% An outer Doin causes SBL to supp$y a Qdummy1 ro! "or ro!s not meeting t#e Doin condition% o data is added or a$tered in t#e tab$e( t#e dummy ro!s e+it on$y "or t#e purpose o" outer Doin 2se t#e outer Doin operator ,?- a"ter t#e tab$e/ co$umn combination in t#e =>E.E c$ause t#at needs t#e dummy ro!s% Cn$y one o" t#e tab$es in a Doin re$ation can be outer Doined% A tab$e can outer Doined to one ot#er tab$e% .o!s t#at do not #a)e a matc# on t#e Doin condition but !#ic# are returned because o" t#e outer Doin may be $ocated by searc#ing o" ro!s !it# 2LL condition% RDER )2 Clause T#e ro!s disp$ayed "rom a &uery do not #a)e any speci"ic order eit#er ascending or descending% *" you !ant t#em to be in ascending or descending order in a particu$ar "ie$d( t#en you can contro$ t#is order "or t#e se$ected ro!s% s&$ =SE"EC' co$umn $ist #R M tab$ename 0/*ERE condition1 RDER )2 co$umn or e+pression 0ASCKDESC1E+amp$e: *" you !ant to s#o! t#e emp$oyee names in descending order "or emp$oyee tab$e( t#en type t#e "o$$o!ing% s&$ =SE"EC' eOcode( eOname( design( basic

#R M emp$oyee /*ERE basic K 2800 RDER )2 eOname DESCG T#e C.DE. BJ c$ause must be t#e $ast c$ause to appear in t#e SBL statement% Since C.ACLE stores ro!s in no particu$ar se&uence( t#e C.DE. BJ c$ause is t#e on$y !ay to retrie)e ro!s in a speci"ic order%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Co$umns t#at are not in t#e SELECT $ist may appear in t#e C.DE. BJ c$ause( pro)ided t#ey are in t#e tab$e% .o!s !it# a 2LL )a$ue in an C.DE. BJ co$umn !i$$ a$!ays be sorted "irst !#et#er ascending or descending !ere speci"ied% SBL !i$$ automatica$$y order t#e output ro!s "rom $o!est to #ig#est order( un$ess you speci"y t#e c$ause DESC% (R &% )2 Clause T#is c$ause te$$s Crac$e to group ro!s based on distinct )a$ues t#at e+ist "or speci"ied co$umns% i%e% *t groups t#e se$ected ro!s based on t#e )a$ue o" e+pression "or eac# ro! and returns a sing$e ro! o" summary in"ormation "or eac# group% sFl =SE"EC' grouped 3by3co$umns "unctions #R M tab$e name (R &% )2 co$umn( co$umn%(%%%%G E+amp$e: .etrie)e t#e product numbers and t#e tota$ &uantity ordered "or eac# product "rom t#e sOorderOdetai$s% sFl =SE"EC' pOno( sum ,&tyOordered- U tota$ &ty CrderedV #R M sOorderOdetai$s (R &% )2 pOnoG (R &%IN( #&NC'I N T#ese "unctions act on a group or set o" ro!s and return one .o! o" summary in"ormation per set% S&M A+( MIN MA6 S'DDE+ +ARIANCE C &N' C &N' 3$5 Computes t#e tota$ )a$ue o" t#e group Computes t#e a)erage )a$ue o" t#e group Computes t#e minimum )a$ue o" t#e group Computes t#e ma+imum )a$ue o" t#e group Computes t#e standard de)iation o" t#e group Computes t#e )ariance o" t#e group Counts t#e number o" non3 2LL )a$ues "or t#e Speci"ied group% Counts t#e number o" ro!s inc$uding t#ose #a)ing 2LL )a$ues "or t#e gi)en condition% %

*A+IN( C"A&SE T#e >AI* E c$ause can be used in conDunction !it# t#e E.C2/ BJ c$ause% >AI* E imposes a condition on t#e group by c$ause( !#ic# "urt#er "i$ters t#e groups created by t#e group by c$ause%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

>AI* E and =>E.E c$auses !or5 in a simi$ar manner% T#e di""erence is t#at =>E.E !or5s on ro!s( !#i$e >AI* E !or5s on groups% E+pression in >AI* E c$ause must be sing$e )a$ue per group%

A5 'able Name: Client9master Description: 2sed to store in"ormation about c$ients% Column Name C$ientOno ame Address1 Adddress2 Ciy /incode State Ba$Odue Data 'ype Iarc#ar2 Iarc#ar2 Iarc#ar2 Iarc#ar2 Iarc#ar2 umber Iarc#ar2 umber Si:e Attributes ; /rimary 5ey/ "irst $etter must start !it# QC1 20 ot u$$ @0 @0 18 A 18 10(2

)5 'able Name: %roduct9master Description: 2sed to store in"ormation about products% Column Name /roductOno Description /Opercent 2Omeasure BtyOonO#and .eorderO$)$ Se$$Oprice CostOprice Data 'ype Iarc#ar2 Iarc#ar2 umber Iarc#ar2 umber umber umber umber Si:e ; 18 <(2 10 A A A(2 A(2 Attributes /rimary 5ey/ "irst $etter must start !it# Q/1 ot u$$ ot u$$ ot u$$ ot u$$ ot u$$ ot u$$( cannot be 0 ot u$$( can not be 0

C5 'able Name: Salesman9master Description: 2sed to store in"ormation about sa$esman !or5ing in t#e company% Column Name SOno SOname Data 'ype Iarc#ar2 Iarc#ar2 Si:e ; 20 Attributes /rimary 5ey/ "irst $etter must start !it# QS1 ot u$$

Address1 Address2

Iarc#ar2 Iarc#ar2

@0 @0

ot u$$
A dreamMAKERS *nitiati)e

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

city /incode State Sa$Oamt TgtOtoOget JtdOsa$es remar5s

Iarc#ar2 umber Iarc#ar2 umber umber umber Iarc#ar2

20 A 20 A(2 ;(2 ;(2 ;0

ot u$$( cannot be 0 ot u$$( cannot be 0 ot u$$

D5 'able Name: Sales9order Description: 2sed to store c$ient1s orders% Column Name
CrderOno CrderOdate C$ientOno De$yOaddr SOno De$yOtype Bi$$edOyn De$yOdate CrderOstatus

Data 'ype
Iarc#ar2 Date Iarc#ar2 Iarc#ar2 Iarc#ar2 C#ar C#ar Date Iarc#ar2

Si:e
; ; 28 ; 1 1 10

Attributes
/rimary 5ey/ "irst $etter must start !it# QC1 Horeign 5ey re"erences c$ientOno o" c$ientOmaster tab$e% Horeign 5ey re"erences sOno o" sa$esmanOmaster tab$e% De$i)ery: part,/- / "u$$ ,H- De"au$t QH1 Cannot be $ess t#an orderOdate Ia$ues,Qinprocess1(1"u$$"i$ed1(1bac5order1(1cance$$ed1-

CrderOn o
C1901 C1902 C<;;8 C190@ C<;;; C190A

CrderOdate C$ientOno SOno


123Zan30; 283Zan30; 1A3"eb30; 0@3Apr30; 203May30; 2<3May30; C001 C002 C00@ C001 C00< C008 S001 S002 S00@ S001 S002 S00@

De$yO Bi$$edOyn type


H / H H / H J J

De$yOdate
203Zan30; 2:3Zan30; 203Heb30; 0:3Apr30; 223May30; 2;3May30;

CrderOstatus
*n /rocess Cance$$ed Hu$$"i$$ed Hu$$"ie$d Cance$$ed *n /rocess

E5 'able Name: Sales9order9details Description: 2sed to store c$ient1s orders !it# detai$s o" eac# product ordered% Column Name CrderOno /roductOno BtyOordered Data 'ype Iarc#ar2 Iarc#ar2 umber Si:e ; ; A
A dreamMAKERS *nitiati)e

Attributes /rimary 6ey/ Horeign 6ey re"erences orderOno o" t#e sa$esOorder tab$e% /rimary 6ey/ Horeign 6ey re"erences productOno o" t#e /roductOmaster tab$e%

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

BtyOdisp /roductOrate

umber umber

A 10(2

rder9no C1901 C1901 C1901 C1902 C<;;8 C<;;8 C<;;8 C<;;8 C190@ C190@ C190A C190A

%roduct9no /001 /002 /00@ /001 /002 /00< /008 /00@ /00; /00< /008 /00:

!ty9ordered < 2 2 10 @ @ 10 < 2 1 1 10

!ty9disp < 1 1 0 @ 1 10 < 2 1 0 0

%roduct9rate 828 A<00 8280 828 @180 8280 828 1080 1080 12000 A<00 1080

!ueries using *aving and (roup )y Clause: 1- /rint t#e description and tota$ &ty so$d "or eac# product% 2- Hind t#e )a$ue o" eac# product so$d% @- Ca$cu$ate t#e a)erage &ty so$d "or eac# c$ient t#at #as a ma+imum order )a$ue o" 18000% <- Hind out t#e sum tota$ o" a$$ t#e bi$$ed orders "or t#e mont# o" Zanuary !ueries on Joins and Correlation: 1- Hind out t#e products( !#ic# #a)e been so$d to Q*)an Bayross1% 2- Hind out t#e products and t#eir &uantities t#at !i$$ #a)e to be de$i)ered in current mont#% @- Hind t#e productOno and description o" constant$y so$d i%e% rapid$y mo)ing products% <- Hind t#e names o" c$ients !#o #a)e purc#ased QCD Dri)e1% 8- List t#e productOno and orderOno o" customers #a)ing &tyOordered $ess t#an 8 "rom t#e sa$esOorderOdetai$s tab$e "or t#e product Q"$oppies1% ;- Hind t#e products and t#eir &uantities "or t#e orders p$aced b Q*)an Bayross1 and QIandana Sait!a$1% :- Hind t#e products and t#eir &uantities "or t#e orders p$aced by c$ientOno QC0011 and QC0021% C NS'R&C'IN( AN EN("IS* SEN'ENCE /I'* DA'A #R M 'A)"E C "&MNS
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

E+amp$e: Create an Eng$is# sentence( by Doining predetermined string )a$ues !it# co$umn data retrie)ed "rom t#e sa$esOorder tab$e% ',e string literals are : Crder o% =as p$aced by C$ient Cn ',e columns are: CrderOno C$ientOno CrderOdate o%

'able Name:

Sa$esOorder rder9no C1001 C1002 C100@ Client9no C001 C002 C00@ rder9date 0<3aug30; 083aug30; 0;3aug30; o177 C$ientOno77 Qon1 77 orderOdate

SE"EC' Qorder no%177 orderOno 77 Q!as p$aced by C$ient #R M sa$esOorderG utput:

Qorderno%177CrderOno771!asp$acedbyc$ientno%177C$ientOno771on177CrderOdate OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO Crder no% C1001 !as p$aced by C$ient no% C001 on 0<3aug30; Crder no% C1002 !as p$aced by C$ient no% C002 on 083aug30; Crder no% C100@ !as p$aced by C$ient no% C00@ on 0;3aug30; 'o avoid a data ,eader t,at appears meaninglessD use an alias as s,o.n belo.: SE"EC' Qorder no%177 orderOno 77 Q!as p$aced by C$ient Qon1 77 orderOdate UCrders p$acedV #R M sa$esOorderG utput: Crders p$aced OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO Crder no% C1001 !as p$aced by C$ient no% C001 on 0<3aug30; &SIN( '*E &NI ND IN'ERSEC' AND MIN&S C"A&SE Union Clause:
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

o177 C$ientOno77

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Mu$tip$e &ueries can be put toget#er and t#eir output combined using t#e union c$ause% T#e union c$ause merges t#e output o" t!o or more &ueries into a sing$e set o" ro!s and co$umns% E+amp$e: .etri)e t#e names o" a$$ t#e c$ients and sa$esman in t#e city o" Qmumbai Q "rom t#e tab$es c$ientOmaster and sa$esmanOmaster% SE"EC' sa$esmanOno( name #R M sa$esmanOmaster /*ERE cityR1mumbai1 &NI N SE"EC' c$ientOno( name #R M c$ientOmaster /*ERE cityR1mumbai1G Intersect Clause: Mu$tip$e &ueries can be put toget#er and t#eir output combined using t#e intersect c$ause% T#e intersect c$ause outputs on$y ro!s produced by bot# t#e &ueries intersected i%e% t#e output in an intersect c$ause !i$$ inc$ude on$y t#ose ro!s t#at are retrie)ed by bot# t#e &ueries% E+amp$e: .etrie)es t#e sa$esman name in Qmumbai1 !#ose e""orts #a)e resu$ted into at $east one sa$es transaction% SE"EC' sa$esmanOno( name #R M sa$esmanOmaster /*ERE cityR1mumbai1G IN'ERSEC' SE"EC' sa$esmanOmaster%sa$esmanOno( name #R M sa$esmanOmaster( sa$esOorder /*ERE sa$esmanOmaster%sa$esmanOno R sa$esOorder%sa$esmanOnoG T#e intersect c$ause pic5s up records t#at are common in bot# &ueries% Minus Clause: Mu$tip$e &ueries can be put toget#er and t#eir output combined using t#e minus c$ause% T#e minus c$ause outputs t#e ro!s produced by t#e "irst &uery( a"ter "i$tering t#e ro!s retrie)ed by t#e second &uery% E+amp$e: .etri)es a$$ t#e product numbers o" non3mo)ing items "rom t#e productOmaster tab$e% 'able name: sa$esOorderOdeati$s
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

rder No C111 C112 C11@ C11< 'able name: productOmaster %roduct No /112 /11@ /11; /11: SE"EC' product no #R M productOmaster MIN&S SE"EC' product no #R M sa$esOorderOdetai$sG

%roduct No /112 /111 /11@ /11<

Description Monitors CD Dri)es 6eyboards >DD

T#e minus c$ause pic5s up records in t#e "irst &uery a"ter "i$tering t#e records retri)ed by t#e second &uery% T#us( t#e output a"ter app$ying t#e M* 2S c$ause !i$$ be: utput: /roduct o OOOOOOOOOOOOOO /11@ /11< !ueries on Constructing Sentences .it, data: 1- /rint in"ormation "rom product3master( sa$esOorderOdetai$ tab$es in t#e "o$$o!ing "ormat "or a$$ records:3 [description\ !ort# .s% [tota$ sa$es "or t#e product\ !as so$d% 2- /rint in"ormation "rom product3master( sa$esOorderOdetai$ tab$es in t#e "o$$o!ing "ormat "or a$$ records:3 [description\ !ort# .s% [tota$ sa$es "or t#e product\ !as ordered in t#e mont# o" [order3 date in mont# "ormat\% @- print in"ormation "rom product3master( sa$esOorder( c$ientOmaster tab$es in t#e "o$$o!ing "ormat "or a$$ t#e records:3 [custOname\ #as p$aced order [orderOno\on [orderOdate\%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

S!" %ER# RMANCE '&NIN(


INDE6ES An inde+ is an ordered $ist o" t#e content o" a co$umn o" a tab$e% *nde+ing a tab$e is an Qaccess strategy1( t#at is a !ay to sort and searc# records in t#e tab$e% *nde+es are essentia$ to impro)e t#e speed !it# !#ic# t#e record can be $ocated and retrie)ed "rom a tab$e% =#en data is inserted in t#e tab$e( t#e orac$e engine inserts t#e data )a$ue in t#e inde+% Hor e)ery data )a$ue #e$d in t#e inde+ t#e orac$e engine inserts a uni&ue R /ID )a$ue% T#e .o!id indicates e+act$y !#ere t#e record is stored in tab$e% T#e .o!id "ormat used by orac$e is as "o$$o!s: )))))));RRRR;#### #### is a uni&ue number gi)en by t#e orac$e engine to eac# data "i$e% Data "i$e are "i$e used by orac$e engine to store user data% ))))))) is t#e b$oc5 number in !#ic# t#e record is stored% T#e data "i$e is di)ided into data b$oc5s and eac# b$oc5 is gi)en a uni&ue number% RRRR is uni&ue record number% Eac# data b$oc5 can store one or more records% T#us eac# record in t#e data b$oc5 is gi)en a uni&ue record number% Creating INDE6: S&$KCREA'E INDE6 inde+Oname N tab$ename ,co$umnname-G E+amp$e: S&$KCREA'E INDE6 id+OcOno N c$ientOmaster,cOno-G Creation of &niFue Inde4:
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

An uni&ue inde+ can a$so be created on one or more co$umns% *" an inde+ is created on a sing$e co$umn it is ca$$ed simp$e 2ni&ue *nde+% S&$KCREA'E &NI!&E INDE6 inde+name N tab$emname ,co$umnname-G =#en t#e user de"ines a primary 5ey or a uni&ue 5ey constraint( t#e orac$e engine automatica$$y creates a uni&ue inde+ on t#e primary 5ey or uni&ue 5ey co$umn% *" an inde+ is created on more t#an one co$umn it is ca$$ed Composite 2ni&ue *nde+% T#e synta+ "or creating a composite uni&ue inde+ is: S&$KCREA'E &NI!&E INDE6 inde+name N tab$emname ,co$umnname( co$umnname-G Dropping INDE6: S&$KDR % INDE6 inde+OnameG Hor eac# ro! returned by &uery( t#e .C= 2M co$umn returns a number indicating t#e record in !#ic# t#e orac$e engine se$ects t#e ro! "rom tab$e% T#e "irst ro! se$ected #as a .C= 2M o" 1( t#e second #as 2 etc% T#e order in !#ic# data is retrie)ed is dependent upon t#e inde+es created on t#e tab$e% *" an inde+ is created on t#e co$umn used * t#e order by c$ause( t#e orac$e engine uses t#e inde+ to retrie)e data in sorted order% T#us t#e .C= 2M !i$$ be in t#e order o" t#e ro!s retrie)ed "rom t#e inde+% *" an inde+ is not created on t#e co$umn used in t#e order by c$ause( t#e orac$e engine !i$$ retrie)e data "rom t#e tab$e in t#e order o" data insertion and t#us an order by c$ause does not a""ect t#e .C= 2M o" eac# ro!% SE!&ENCES Most app$ication re&uires automatic generation o" numeric )a$ue% A se&uence is a database obDect t#at generates automatic se&uence number "or ro!s in tab$es% Crac$e pro)ides an obDect ca$$ed a se&uence t#at can generate numeric )a$ues% T#e )a$ue generated can #a)e a ma+imum o" @A digits% A se&uence can be de"ined to: Eenerate numbers in ascending or descending% /ro)ide inter)a$s bet!een numbers
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Cac#ing o" se&uence numbers in memory etc% T#is in"ormation is pro)ided to orac$e at t#e time o" se&uence generation% T#e SBL statement used "or creating se&uence is: S&$KCREA'E SE!&ENCE se&uenceOname L INCREMEN' )2 integer)a$ue S'AR' /I'* integer)a$ue MA6+A"&E integer)a$ue / N MA6+A"&E MIN+A"&E integer)a$ue / N MIN+A"&E C2C"EK N C2C"E CAC*E integer)a$ue/ N CAC*E RDER K N RDERN SeFuence is al.ays given a name so t,at it can be referenced later .,en reFuired; E+amp$e: Create se&uence orderOse&( !#ic# !i$$ generate numbers "rom 1 to 9999 in ascending order !it# an inter)a$ o" 1% T#e se&uence must restart "rom t#e number 1 a"ter generating number 9999% S&$KCREA'E SE!&ENCE orderOse& L INCREMEN' )2 1 S'AR' /I'* 1 MIN+A"&E 1 MA6+A"&E 9999 C2C"EKey.ords * C.EME TED BJ Description Speci"ies t#e inter)a$ bet!een se&uence numbers% *t can be positi)e or negati)e )a$ue but not 'ero% *" t#is c$ause is omitted t#e de"au$t )a$ue is 1% Speci"ies t#e se&uence minimum )a$ue% Speci"ies t#e ma+imum )a$ue t#at t#e se&uence can generate% Speci"ies t#e "irst se&uence number to be generated% T#e de"au$t "or a ascending se&uence is t#e minimum )a$ue ,1- and "or a descending se&uence( it is t#e ma+imum )a$ue ,31-% Speci"ies t#at t#e se&uence continue to generate repeat )a$ues a"ter reac#ing eit#er its ma+imum )a$ue% Speci"ies se&uence cannot generate more )a$ues a"ter reac#ing t#e ma+imum )a$ue%
A dreamMAKERS *nitiati)e

M* IAL2E MAWIAL2E STA.T =*T>

CJCLE C CJCLE

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

CAC>E CCAC>E

Speci"ies #o! many )a$ues o" a se&uence orac$e pre a$$ocate and 5eeps in memory "or "aster access% T#e minimum )a$ue "or t#is parameter is t!o% Speci"ies t#at )a$ue o" a se&uence are not pre3a$$ocated%

If t,e CAC*E K N CAC*E clause is omitted oracle cac,es >H seFuence numbers by default; ',e RDER K N RDER clause ,as no significanceD if oracle is configured .it, single server option; It is useful only .,en you are using %arallel Server in %arallel mode option; Referencing a SeFuence: Cnce a se&uence is created SBL can be used to )ie! t#e )a$ues #e$d in its cac#es% To simp$y )ie! se&uence )a$ue use a se$ect sentence as described be$o!% S&$KSE"EC' se&uenceOname%ne4tval #R M dua$G T#is !i$$ disp$ay t#e ne+t )a$ue #e$d in t#e cac#e on t#e ID2 screen% E)ery time ne4tval re"erences a se&uence its output is automatica$$y incremented "rom t#e o$d )a$ue to t#e ne! )a$ue ready "or use% A"ter creating a tab$e you can add t#e data by using t#e * SE.T command $i5e t#is: S&$KINSER' IN' sa$esOorder,oOno( oOdate( cOno+A"&ES ,orderOse&%ne+t)a$( sysdate( Qc00011-G To re"erences t#e current )a$ue o" a se&uence: S&$KSELECT se&uenceOname%currval H.CM dua$G Altering A SeFuence A se&uence once created can be a$tered% T#is is ac#ie)ed by using t#e ALTE. SEB2E CE command% S&$KA"'ER SE!&ENCE se&uenceOname L INCREMEN' )2 integer)a$ue

S'AR' /I'* integer)a$ue MA6+A"&E integer)a$ue / N MA6+A"&E MIN+A"&E integer)a$ue / N MIN+A"&E C2C"EK N C2C"E CAC*E integer)a$ue/ N CAC*E RDER K N RDERN
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

E+amp$e: C#ange t#e cac#e )a$ue o" t#e se&uence orderOse& to @0 and inter)a$ bet!een t!o numbers as 2% S&$KA"'ER SE!&ENCE orderOse& INCREMEN'ED )2 2 CAC*E @0G Dropping A SeFuence T#e D.C/ SEB2E CE command is used to remo)e t#e se&uence "rom t#e database% S&$KD.C/ SEB2E CE se&uenceOnameG +ie.s T#e tab$e o" a database de"ines t#e structure and t#e organi'ation o" its data% Cnce t#ey are de"ined t#ey a$!ays present t#e data in a particu$ar !ay% A"ter a tab$e is created and popu$ated !it# data( it may become necessary to pre)ent a$$ users "rom accessing a$$ co$umns o" a tab$e( "or data security reason% T#is !ou$d mean creating se)era$ tab$es #a)ing t#e appropriate number o" co$umns and assigning speci"ic users to eac# tab$e( as re&uired% Sometimes in app$ication( a di""erent )ie! o" t#e data or t#e in"ormation in a di""erent "ormat is desired% T#is is #and$ed in C.ACLE using I*E=S%

A I*E= is a )irtua$ tab$e in t#e database !#ose contents are de"ined by a &uery it can represent% A )ie! #o$ds no data at a$$( unti$ a speci"ic ca$$ to t#e )ie! is made% T#is reduce redundant data on a >DD to a )ery $arge e+tent%
C,aracteristics of a vie. De"ine !it# any SELECT statement% Stored in t#e data dictionary in t#e tab$e ca$$ed 2SE. I*E=S% Iie!s do not e+it p#ysica$$y% T#ey are )irtua$ tab$es t#at e+it on$y as de"initions record in t#e system cata$ogue% Creation of vie.s: S&$KCREA'E +IE/ )ie!name AS SE"EC' co$umnname( co$uimnname #R M tab$ename /*ERE co$umnnameRe+pression $istG (R &% )2 grouping criteria *A+IN( predicate
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

',e

RDER )2 clause cannot be used .,ile creating a vie.;

E+amp$e: Create )ie! on t#e c$ientOmaster tab$e "or t#e Administration Department% S&$KCREA'E +IE/ )!Oc$ientadmin AS SE"EC' name( adddress1( address2( city( pincode( state #R M c$ientOmasterG Selecting a data set from a vie.: Cnce a )ie! #as been created( it can be &ueried e+act$y $i5e a base tab$e% S&$KSE"EC' co$umnname( co$umnname #R M )ie!nameG T#e se$ect statement can #a)e t#e c$ause $i5e =>E.E( C.DE. BJ etc% E+amp$e: S&$KSE"EC' name( address1( address2( city( pincode( state #R M )!Oc$ientadmin /*ERE city * ,QMe#sana1( Q/atan1-G Destroying a vie.: T#e D.C/ I*E= commnd is used to remo)e a )ie! "rom t#e database% S&$KDR % +IE/ )ie!nameG Advantages of using vie.s Security: Eac# user can be gi)en permission to access t#e database on$y t#roug# a sma$$ set o" )ie!s t#at contain t#e speci"ic data% T#e user is aut#ori'ed to see( rat#er t#an t#e entire tab$e( t#us restricting t#e user1s access to stored data% !uery Simplicity: A )ie! can dra! data "rom se)era$ di""erent tab$es and present it to t#e user as a sing$e tab$e( turning !#at !ou$d #a)e been mu$ti3tab$e &ueries into simp$e sing$e tab$e &ueries against t#e )ie!% Insulation from c,anges: A )ie! can present a consistent( unc#anged image o" t#e structure o" t#e database( e)en i" t#e under$ying tab$es are sp$it( reconstructed or renamed% Data integrity:
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

*" t#e data is accessed and entered t#roug# a )ie!( t#e DBMS can automatica$$y c#ec5 t#e data to ensure t#at it meets speci"ied integrity constraint% Disadvantages of vie.s %erformance: Iie! creates t#e appearance o" a tab$e( but t#e DBMS must sti$$ trans$ate t#e &ueries against t#e )ie! into t#e &ueries against t#e under$ying source tab$es% *" t#e )ie! is de"ined by a comp$e+ mu$ti3Doin( t#en it may ta5e $ong time to carry out% &pdate restrictions: More comp$e+ )ie!s can not be used to update t#e under$ying source tab$es t#ey are Qread on$y1% (RAN'IN( AND RE+ KIN( %ERMISSSI NS CbDects t#at are created by a user are o!ned and contro$$ed by t#at user% *" a user !is#es to access any o" t#e obDects be$onging to anot#er user( t#e o!ner o" t#e obDect !i$$ #a)e to gi)e t#e permission "or eac# access% T#is is ca$$ed Granting of Privileges. /ri)i$eges once gi)en can be ta5en bac5 by t#e o!ner o" t#e obDect% T#is is ca$$ed Revoking of Privileges. (ranting %rivileges using t,e (RAN' statement; T#e Erant statement pro)ides )arious types o" access to database obDects suc# as tab$es( )ie!s and se&uences% S&$K(RAN' obDect pri)i$eges N obDect name ' username L/I'* E.A T C/T*C N CBZECT /.*I*LEEES: Eac# obDect pri)i$eges t#at are granted aut#ori'e t#e grantee to per"orm some operation on t#e obDect% T#e user can grant t#e pri)i$eges or grant on$y speci"ic obDect pri)i$eges% T#e $ists o" obDect pri)i$eges are as "o$$o!s: ALTE. DELETE * DEW * SE.T : a$$o!s t#e grantee to c#ange t#e tab$e de"inition !it# t#e ALTE. TABLE command% : a$$o!s t#e grantee to remo)e t#e record "rom a tab$e !it# t#e DELETE Command% : a$$o!s t#e grantee to create an inde+ on t#e tab$e !it# t#e * DEW Command% : a$$o!s t#e grantee to add records to t#e tab$e !it# t#e * SE.T
A dreamMAKERS *nitiati)e

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

SELECT 2/DATE

Command% : a$$o!s t#e grantee to &uery t#e tab$e !it# t#e SELECT Command% : a$$o!s t#e grantee to modi"y t#e records in t#e tab$e !it# t#e 2/DATE Command%

=*T> E.A T C/T*C : T#e =*T> E.A T C/T*C a$$o!s t#e grantee to in turn grant obDect pri)i$eges to ot#er users% E+amp$e: Ei)e t#e user /radeep a$$ data manipu$ation permission on t#e tab$e productOmaster% S&$K(RAN' A"" C productOmaster TC pradeepG Ei)e t#e user Mita on$y t#e permission to )ie! and modi"y records in t#e tab$e c$ientOmaster% S&$K(RAN' se$ect( update C c$ientOmaster ' MitaG RevoLing %rivileges (iven: /ri)i$eges once gi)en can be denied to a user using t#e .EIC6E command% S&$KRE+ KE obDect pri)i$eges N obDect name #R M username E+amp$e: Ta5e bac5 a$$ pri)i$eges on t#e tab$e bonous "rom H$orian% S&$KRE+ KE ALL N bonous #R M H$orianG

'RANSCA'I N %R CESSSIN( IN S!"


C.ACLE a$$o!s t#e grouping o" indi)idua$ c#anges done t#roug# t#e use o" SBL commands $i5e SELECT( * SE.T( 2/DATE or DELETE( * TC $ogica$ transactions to ensure data consistency and integrity% Transaction is a $ogica$ unit o" !or5 or a se&uence o" $ogica$ operations or e)ent !#ic# is treated as a sing$e unit% *n ot#er !ords( transaction is a series o" SBL statements t#at eit#er succeed or "ai$ as a unit%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

=#en you manipu$ating t#e data in t#e database( t#e c#anges made by you are not norma$$y made permanent in t#e database unti$ you gi)e a command to do so or you e+it orac$e% Saving t,e c,anges in t,e transaction Jou can ma5e c#anges permanent in t#e database by using% SFl= C MMI' 0/ RK1=C.6 is optiona$ and on$y pro)ided "or readabi$ity% Ho$$o!ing t#ings #appen !#en you issue CCMM*T% T#e c#anges are permanent in t#e database% T#e transaction is mar5ed as c$osed% e! transaction is started%

Any $oc5s ac&uired by t#e transaction are re$eased% &ndo t,e c,anges made in t,e transaction *t may so #appen t#at you may not !ant to ma5e t#e data permanent in t#e database( due to t#e "ai$ing o" some SBL statement in a se&uence or !rong in"ormation pro)idedG t#en you may use t#e command .CLLABAC6 to discard t#e c#ange made%

SFl=R "")ACK 0/ RK1Ho$$o!ing t#ings #appen !#en you use .CLLBAC6: Any c#anges made by t#e transaction are undone( as i" it #adn1t been issued% e! transaction is started%

Any $oc5s ac&uired by t#e transaction are re$eased% .CLLBAC6 statement undoes t#e entire transaction% *" you !ant to undo on$y part o" t#e transaction( t#en it can be done by using SFl=SA+E% IN' nameDuring t#e transaction i" you !ant to undo t#e c#anges up to certain sa)epoint( you #a)e to gi)e t#e .CLLBAC6 command $i5eP
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

SFl=R "")ACK 0/ RK1 '

SA+E% IN' name-

Ho$$o!ing t#ings #appen !#en you issue .CLLBAC6 TC SAIE/C* T% T#e c#anges made by t#e statement issued a"ter t#e sa)epoint( are undone% T#e sa)epoint remains acti)e( so it can be ro$$ed bac5 to again i" desired% Any $oc5s and resources ac&uired by t#e SBL statements since t#e sa)e point are re$eased% T#e transaction is sti$$ acti)e as t#ere are SBL statements pending% Sa)epoint are use"u$ in interacti)e programs( because you can create and name intermediate steps o" a program% T#is a$$o!s you more contro$ o)er $onger( more comp$e+ program% Introduction to %"KS!":3 /L/SBL stands "or /rocedura$ Language/Structured Buery Language% *t is standard procedura$ $anguage t#at #e$ps user by combining t#e po!er and "$e+ibi$ity o" SBL !it# )arious procedura$ construct% A /L/SBL segment is ca$$ed a b$oc5% A b$oc5 consists o" t#ree sections% T#ese sections are: 1- Dec$are section% 2- Begin section% @- E+ception section% <- End section% Declare section :3 Code b$oc5 start !it# a dec$aration section( in !#ic# memory )ariab$e and ot#er Crac$e obDect can be dec$ared( and i" re&uired initia$i'ed% Cnce dec$ared(t#ey can be used in t#e SBL statement "or data manipu$ation% )egin section:I *t consists o" a set o" SBL and /L/SBL statements( !#ic# describe processes t#at #a)e to be app$ied to data% Actua$ data manipu$ation( retrie)a$( $ooping and branc#ing construct are speci"ied in t#is section% E4ception section:I T#is section dea$s !it# #and$ing o" errors t#at arise during e+ecution o" t#e data manipu$ation statements !#ic# ma5e up t#e /L/SBL code b$oc5% Errors can arise due to synta+( $ogic and/or )a$idation ru$e )io$ation% End section:I T#is mar5 t#e end o" a /L/SBL b$oc5%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e
4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

)locL Structure:3 DEC"ARE MDeclaration of memory variableD constantsD cursors= )E(IN ME4ecutable statement= E6CE%'I N ME4ception ,andlers= END%"KS!" Control Structure:I /L/SBL #as a )ariety o" contro$ structures t#at a$$o! you to contro$ t#e be#a)ior o" t#e b$oc5 as it runs% I#I'*ENIE"SE statements I# M)oolean E4pression= ',en SeFuence of statementsE"SI#M)oolean E4pression= ',en SeFuence of statementsE"SE SeFuence of statementsEND I#" " %S:I % SeFuence of statementE6I' 0/*EN condition1END " %/*I"EMcondition=" % SeFuence of statementEND " %# RMvariable=INMlo.er value=;;M&pper value=" SeFuence of statementEND " %%"KS!" Data 'ypes:I T#e de"au$t data types t#at can be dec$ared in /L/SBL are date% umber( C#ar( and Iarc#ar2( Boo$ean( %

A'2%E attribute is used !#en you !ant a )ariab$e to #a)e t#e same data type as t#at o" co$umn o" a tab$e% 2sing Stype #as t#e ad)antage t#at !#ene)er t#e type and/or
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e
4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Si'e o" a co$umn in t#e tab$e is c#angedG it is automatica$$y re"$ected in t#e )ariab$e% Hor e+amp$e t#e "o$$o!ing statement dec$ares )ariab$e NAME to #a)e t#e same data type as t#at o" t#e co$umn EM%9NAME o" EM%" 2EE tab$e% NAME EM" 2EE;EM%9NAMEA'2%E-

AR /'2%E attribute is used !#en you !ant t#e )ariab$e to #o$d t#e )a$ues o" an entire ro! o" a tab$e% *n case )ariab$es "or t#e entire ro! o" a tab$e need to be dec$ared( t#e instead o" dec$aring t#em indi)idua$$y( AR /'2%E s#ou$d be used in "o$$o!ing manner% EM%9R / EM%" 2EEAR /'2%E

T#e abo)e statement dec$ares EM%9R / )ariab$e as composite )ariab$e consisting o" t#e co$umn names o" t#e EM%" 2EE tab$e as its members% *t is capab$e o" storing one !#o$e ro! o" a tab$e% To re"er to a )a$ue in t#e ro!( say ENAME a 3;5 "o$$o!ed by t#e co$umn name is used as s#o!n be$o!: EM%9R /;ENAME:78A)C8Advantages of %"KS!": 1% /L/SBL is de)e$opment too$ t#at not on$y supports SBL data manipu$ation but a$so pro)ides "aci$ities o" conditiona$ c#ec5ing( branc#ing and $ooping% 2% /L/SBL sends an entire b$oc5 o" statements to t#e Crac$e engine at one time% T#e communication bet!een t#e program b$oc5 and t#e Crac$e engine reduces considerab$y% T#is in turn reduces net!or5 tra""ic% T#e Crac$e engine gets t#e SBL statements as a sing$e b$oc5( and #ence it processes t#is code muc# "aster t#an i" it got t#e code one sentence at a time% @% /L/SBL a$so permits dea$ing !it# errors as re&uired( and "aci$itates disp$aying user3"riend$y messages( !#en errors are encountered% <% /L/SBL a$$o!s dec$aration and use o" )ariab$e in b$oc5 o" code% T#ese )ariab$es can be used to store intermediate resu$ts o" a &uery "or "aster processing( or ca$cu$ate )a$ues and insert t#em into an Crac$e tab$e% 8% App$ication !ritten in /L/SBL is portab$e to any computer #ard!are and operating system( !#ere orac$e is operationa$% %rogram: 1% =rite a /L/SBL code to print numbers 1 to A% A$so insert t#e resu$t into a tab$e TEM/( #a)ing one co$umn o" 2MBE. data type% 2% =rite /L/SBL code to ca$cu$ate t#e area o" a circ$e "or a )a$ue o" radius )arying "rom @ to :% Store t#e radius and t#e corresponding )a$ues o" ca$cu$ated area in an empty tab$e named A.EA( consisting o" t!o co$umns radius and area% @% =rite a /L/SBL b$oc5 to "ind t#e "actoria$ o" a gi)en number% <% =rite a /L/SBL code to insert a$$ t#e detai$s o" t#e emp$oyee !#ose code is 10: to a ne! tab$e EM/ !#ic# #as same structure as EM/LCJEE tab$e%
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e
4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

8% =rite a /L/SBL code b$oc5 t#at !i$$ accept an account number "rom t#e user( c#ec5 i" t#e user1s ba$ance is $ess t#an t#e minimum ba$ance( on$y t#en deduct .s% 100/3 "rom t#e ba$ance% T#e process is "ired on t#e ACCOMST. tab$e% Cursor:I T#e Crac$e engine uses a !or5 area "or its interna$ processing in order to e+ecute an SBL statement% T#is !or5 area is pri)ate to SBL1s operation and is ca$$ed as Cursor% T#e SBL statement are e+ecuted in t#is !or5 area and Buery resu$ts are a$so stored in t#is !or5 area% T#e date t#at is stored in t#e cursor is ca$$ed t#e Acti)e Data set% =#en cursor is $oaded !it# mu$tip$e ro!s )ia &uery t#e Crac$e engine open and maintains a ro! pointer% Depending on user re&uest to )ie! data t#e ro! pointer !i$$ be re$ocated !it#in t#e cursor1s Acti)e Data Set% T#e Crac$e a$so maintains t#e cursor )ariab$es and t#e )a$ues #e$d in t#ese )ariab$es indicate t#e status o" t#e processing being done by t#e cursor% Depending upon t#e circumstances under !#ic# t#ey are opened t#ere are t!o types o" cursor% 1- *mp$icit Cursor 2- E+p$icit Cursor

Implicit cursor: I T#e orac$e engine imp$icit$y opens a cursor on t#e ser)er to process eac# SBL statement% *mp$icit cursor is opened and managed by t#e Crac$e engine interna$$y( t#e "unction o" reser)ing an area in memory( popu$ating t#is area !it# appropriate data( processing t#e data in memory area( re$easing t#e memory area !#en t#e processing is comp$ete is ta5en care o" by t#e Crac$e engine% T#e resu$tant data is t#en passed to t#e c$ient )ia net!or5% *mp$icit cursor attributes can be used to access in"ormation about t#e status o" $ast insert (update ( de$ete or sing$e ro! se$ect statement%

Implicit cursor Attributes: I AIS %EN: 3 T#e Crac$e engine automatica$$y opens and c$ose t#e SBL cursor a"ter e+ecuting its associated se$ect( insert( de$ete and update SBL statement% A# &ND: I E)a$uate to T.2E( i" an insert( update or de$ete a""ected one or more .o!s( or a sing$e3ro! se$ect returned one or more ro!s% Ct#er!ise it e)a$uates to HALSE% AN '# &ND: I *t is t#e $ogica$ opposite o" SHC2 D% *t e)a$uates to T.2E( i" an insert( update or de$ete a""ected no ro!s( or a sing$e3ro! se$ect returns no ro!s% Ct#er!ise it e)a$uate to HALSE% AR /C &N': I .eturns t#e number o" ro!s a""ected by an insert( update or de$ete or se$ect into statement%

E4plicit Cursor: I
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

E+p$icit cursors are user de"ined cursor% T#e cursor is opened and managed by t#e user% T#is cursor !i$$ be dec$ared and mapped to an SBL &uery in t#e Dec$are section o" t#e /L/SBL b$oc5 and used !it#in t#e E+ecutab$e Section% Cursor Management:I Dec$are a cursor mapped to a SBL se$ect statement t#at retrie)es data "or processing% Cpen cursor Hetc# data "rom t#e cursor one ro! at a time into memory )ariab$es% /rocess t#e data #e$d in t#e memory )ariab$es as re&uired using a$oop% E+it "rom t#e $oop a"ter processing is comp$ete% C$ose t#e cursor%

*andling of Cursor:I A cursor is de"ined in t#e dec$arati)e part o" /L/SBL b$oc5% T#is is done by naming t#e cursor and mapping it to a &uery% Synta+: C&RS R cursorname IS S!" select statementT#e t#ree statements t#at are used to contro$ t#e cursor are open( "etc# and c$ose% pen statement: Cpening a cursor e+ecute t#e &uery and creates t#e acti)e set t#at contains a$$ ro!s( !#ic# meet t#e &uery searc# criteria% An Cpen statement retrie)es records "rom a database tab$e and p$aces t#e records in t#e cursor% A cursor is opened in ser)er memory% Synta+: %EN cursorname-

#etc, Statement: T#e Hetc# statement retrie)es t#e ro!s "rom t#e acti)e set opened in t#e ser)er into memory )ariab$es dec$ared in t#e /L/SBL code b$oc5 on t#e c$ient one ro! at a time% T#e memory )ariab$es are opened on t#e c$ient mac#ine% Eac# time a "etc# is e+ecuted( t#e cursor pointer is ad)anced to t#e ne+t ro! in t#e Acti)e Data Set% A standard $oop structure ,LoopP%End $oop- is used to "etc# records "rom t#e cursor into memory )ariab$es one ro! at a time% Synta+: #E'C* cursorname IN' variable<D variable>DE;A dreamMAKERS *nitiati)e

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

Close statement: T#e c$ose statement disab$es t#e cursor and t#e acti)e date set becomes unde"ined% T#is !i$$ re$ease t#e memory occupied by t#e cursor and data set bot# on t#e C$ient and on t#e Ser)er% Synta+: C" SE cursorname-

E4plicit Cursor Attributes: I AIS %EN: I E)a$uate to T.2E( i" an e+p$icit cursor is open( or to HALSE( i" it is c$osed%
CursornameAIS %EN; A# &ND: I E)a$uate to T.2E( i" t#e $ast "etc# succeeded because a ro! !as a)ai$ab$e( or to HALSE( i" t#e $ast "etc# "ai$ed because no more ro!s !ere a)ai$ab$e% CursornameA# &ND% AN '# &ND: I E)a$uate to T.2E( i" t#e $ast "etc# #as "ai$ed because no more ro!s !ere a)ai$ab$e( or to HALSE( i" t#e $ast "etc# returned a ro!% CursornameAN '# &ND; AR /C &N': I .eturns t#e number o" ro!s "etc#ed "rom t#e acti)e data set% *t set to 'ero( !#en t#e cursor is opened% CursornameAR /C &N'; %arameteri:ed Cursor Commercia$ app$ication re&uire t#at t#e &uery( !#ic#( de"ines t#e cursor( be generic and t#e data t#at is retrie)ed "rom t#e tab$e be a$$o!ed to c#ange according to need% Crac$e recogni'es t#is and permits t#e creation o" a parameteri'ed cursor prior opening% >ence t#e content o" t#e opened cursor !i$$ constant$y c#ange depending upon a )a$ue passed% Since t#e cursor accepts )a$ues or parameter it is ca$$ed as Parameterized Cursor. T#e parameters can be eit#er a constant or a )ariab$e% Declaring a %arameteri:ed Cursor: Synta+: C&RS R cursorOname,)ariab$eOname data type- is MSE"EC' statementPK pening a %arameteri:ed cursor and passing values to t,e cursor : Synta+:
C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

TE102/Datbase Management Systems

%EN cursorOname,)a$ue/)ariab$e/e+pression%rogram: 1% =rite /L/SBL code t#at uses a cursor to $ist t#e "our #ig#est paid emp$oyees "rom t#e emp$oyee tab$e% 2% =rite a /L/SBL code t#at retrie)e a number "rom t!o tab$es( t#en insert t#e sum o" t#e numbers into a t#ird tab$e% *t stops !#en a$$ ro!s #a)e been retrie)ed "rom bot# tab$es% @% =rite a /L/SBL code t#at using a cursor t#at disp$ay t#e detai$s o" t#ose emp$oyees "rom emp$oyee tab$e !#o #a)e Doined a"ter 1013Dan30:1% All ',e )est 'eam C>C

C2C 0 *ndia1s Most 2ni&ue *ndustry3Academia /artners#ip /rogram

A dreamMAKERS *nitiati)e

4 Copyrig#t Dreamma5ers Career So$utions /)t% Ltd% T#e present document( in a$$ aspects( is a product o" dM 6no!$edge De)e$opment Team% o part o" t#is document( $ogos( grap#ics( content( statements( "igures( statistics s#ou$d be pub$is#ed / copied / reproduced !it#out a prior !ritten consent% Corporate ffice: Dreamma5ers Career So$utions /)t% Ltd% 7 EC389( Sector 1( Sa$t La5e City( 6o$5ata 3 :000;<( =est Benga$( * D*A !!!%dmc2c%com 7 !!!%dmconsu$ting%in 7 C2C >e$p$ines: ?91392@0A;A0@0/2/@

You might also like