Cse 532 Adbms Labmanual 2014 (1)

download Cse 532 Adbms Labmanual 2014 (1)

of 16

Transcript of Cse 532 Adbms Labmanual 2014 (1)

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    1/16

    CSE- 511

    COMPUTINGLAB I

    ADBMS

    I semester M.Tech(CSE)

    201

    Prepared By (Dr. Dinesh Acharya U)

    Approved By(HOD)

    De!t "# C"m!$ter Sc%e&ce ' E&%&eer%&

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    2/16

    O*ect%+es,

    1. Experiments covering the study o re!ationa! data"ase eatures#. Experiments covering the study o o"$ect%Based data"ase eatures

    &. Experiments covering study o O'AP and '

    O$t%&e,

    1. Design o *e!ationa! Data"ase (1 +ee,)#. -' (1 +ee,)&. P'/-'(1 +ee,)

    0. O"$ect%Based Data"ases (# +ee,s). O'AP(# +ee,s)2. '(1 +ee,)

    #

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    3/16

    1. Des%& "# e/t%"&/ D/t/ B/se

    [Referppt slides in Tutorial Week1]1.1 3onsider the o!!o4ing set o re5uirements or a university data"ase that is used to,eep trac, o students6 transcripts7

    (a) 8he university ,eeps trac, o each student6s name9 student num"er9 socia! securitynum"er9 current address and phone9 permanent address and phone9 "irthdate9 sex9 c!ass(reshman9 sophomore9 ...9 graduate)9 ma$or department9 minor department (i any)9 anddegree program (B.A.9 B.-.9 ...9 Ph.D.). -ome user app!ications need to reer to the city9state9 and :ip o the student6s permanent address9 and to the student6s !ast name. Bothsocia! security num"er and student num"er have uni5ue va!ues or each student.

    (") Each department is descri"ed "y a name9 department code9 oice num"er9 oicephone9 and co!!ege. Both name and code have uni5ue va!ues or each department.

    (c) Each course has a course name9 description9 course num"er9 num"er o semesterhours9 !eve!9 and oering department. 8he va!ue o course num"er is uni5ue or eachcourse.

    (d) Each section has an instructor9 semester9 year9 course9 and section num"er. 8he sectionnum"er distinguishes dierent sections o the same course that are taught during the samesemester/year; its va!ues are 19 #9 &9 ...; up to the num"er o sections taught during eachsemester.

    (e) A grade report has a student9 section9 !etter grade9 and numeric grade (

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    4/16

    Assignment Day #1.&.3onvert the o!!o4ing E* mode! o Hospita! data"ase into a re!ationa! schema

    1.0 3onsider the universa! re!ation *?@A9B939D9E9=99H99C and the set o unctiona!dependencies ? A9B % 3; B9D%E9=; A9D%9H; A%; H%C. +hat is the ,ey or *FDecompose * into #>= and then &>= re!ations.

    1. >orma!i:e the given ta"!e to #>= and & >=Detai!s7HappyHome supermar,et dea!s 4ith groceries9 househo!d items9 stationary products andgit items. 8hey have announced a summer me!a 4here9 or every customer 4ho ho!ds amem"ership 4ith HappyHome9 any three items can "e ta,en or ree. 8he tota! price othe three items shou!d "e e5ua! to or "e!o4 rs.1

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    5/16

    1.2 3onsider the o!!o4ing re!ation or pu"!ished "oo,s7

    BOO (Boo,Itit!e9 Authorname9 Boo,Itype9 'istprice9 AuthorIai!9 Pu"!isher)

    AuthorIai! reeres to the ai!iation o the author. -uppose the o!!o4ing dependenciesexist7Boo,Itit!e % Pu"!isher9 Boo,ItypeBoo,Itype % 'istpriceAuthorIname % Author%ai!

    (a) +hat norma! orm is the re!ation inF Exp!ain your ans4er.(") App!y norma!i:ation unti! you cannot decompose the re!ations urther. -tate thereasons "ehind each decomposition.

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    6/16

    #.-'

    2.1 O+er+%e "# S P$s c"mm/&3s /&3 DDL

    [Refer Tutorial Week2/2a]

    2.2 4r%te the SL c"mm/&3s t" cre/te / 3/t//se schem/ #"r the #""%&

    re/t%"&/ schem/7

    CUSTOME (CUST6ID7 CUST6NAME7 ANNUAL6E8ENUE7 CUST6T9PE)

    3U-8ID must "e "et4een 1

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    7/16

    1. 3ities o popu!ation over 1 mi!!ion 4hich have received a 1

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    8/16

    &. P'/-'

    [Refer Tutorial Week 3]1. +rite a P'/-' procedure that accepts a sing!e positive num"er as input9 and

    prints out the actoria! o that num"er.#. Hand!e the division%"y%:ero exception in the invertunction 4hich computes

    inverse o the given num"er&. Hand!e no%data%ound exception in a simp!e procedure9 "a!ance( 3>ame >

    JA*3HA*#9 Ba!ance OU8 >UBE*) that prints the "a!ance or a speciiedcustomer rom the simp!e "an,ing data"ase.

    0. ive a procedure on "an,ing data"ase to inc!ude too%many%ro4s exception.. +rite a saeQ 4ithdra4a! procedure9 4ithdra4a!( Acc>o > JA*3HA*#9

    Amount > >UBE*) on Account ta"!e. 3hec, or suicient "a!ance andupdate the "a!ance. Use an exception to hand!e the case o attempting to

    overdra4 an account2. +rite a procedure9 transfer(giveAccNo IN VARCHAR2, receiveAccNor IN

    VARCHAR2,amount IN NUMBER)to transer money rom one person6s account to

    another. 3hec, or the transer amount "eing negative and chec, 4hether thegiverhas suicient unds to a!!o4 the transer.

    M. 3reate a pac,age "y inc!uding e4 procedures / unctions deined a"ove anddemonstrate the usage o the same.

    N. ive a procedure *ichPoor(Amount >um"ers)9 that iterates through theAccounts8a"!e and c!assiies customers as "eing either RrichR or RpoorR (our

    deinition o rich is anyone 4ho has more than *s.#ame S Address". 3ustomer 'istc. 8ota! Deposits

    1

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    9/16

    4ith the -ystem Date.1&. nc!ude the Payments(!oanInum"er9 paymentInum"er9 paymentIdate9

    paymentIamount). ta"!e into Ban, Data"ase o 'a"1. +rite a trigger to updatethe corresponding ro4 in the !oan ta"!e9 4henever a customer does the !oanpayment.

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    10/16

    0. O"$ect%Based Data"ase

    [Refer Tutorial Week 4]

    O*ect T>!es /&3 O*ect e/t%"&/ T/es,1. 3reate an o"$ect type personQ that contains name and phone num"er. 3reate an

    o"$ect ta"!e personIta"!eQ or this type. nsert ive ro4s into this ta"!e using "oththe methods(re!ationa! and o"$ect re!ationa!) o insertion.

    #. 3reate a type R$o"R 4ith our co!umns7 R$o"tit!eR9 R$o"IDR9 Rsa!aryIamountR andRyearsIoIexperienceR. 3reate an o"$ect ta"!e R$o"Ita"!eR or this type. nsert ro4s into this ta"!e.

    &. 8ry dierent se!ect statements on "oth ta"!es9 such asR-E'E38 =*O ...R9R-E'E38 name =*O ...R9R-E'E38 p.name =*O ...R9R-E'E38 JA'UE(p) =*O ...R

    O*ect T>!e /s User De#%&e3 T>!es,

    0. 3reate an o"$ect type RaddressR that contains street name9 num"er9 !at num"er9city9 posta! code9 and country in a manner so that street name9 num"er and !atnum"er are c!ose!y re!ated(use user deined data type) and country is separaterom a!! the other attri"utes.

    . Drop RpersonR and RpersonIta"!eR. 3reate a type RpersonR 4hich contains irstname9 midd!e initia!9 !ast name9 phone ("usiness9 home9 mo"i!e) and address(rom exercise 0). a,e sure that irst name9 midd!e initia!9 !ast name are c!ose!yre!ated and that the phone num"ers are c!ose!y re!ated to each other.3reate ano"$ect ta"!e RpersonIta"!eR that corresponds to RpersonR.nsert ive ro4s o data into RpersonR. (>ote7 you6!! have to use the o"$ect%re!ationa! orm o insertion).

    I&her%t/&ce,2. 3reate a type Remp!oyeeR under RpersonR that has an additiona! attri"ute

    RempIDR o type >8. 3reate it as >O8 =>A'. 3reate a correspondingemp!oyeeIta"!e and insert & ro4s into it.

    M. A!ter "oth the emp!oyeeIta"!e and the $o"Ita"!e (rom exercise #) so that theyhave primary ,eys.

    e#ere&ces ? E@s,

    N. 3reate the emp!oyment ta"!e using *E=s insert & ro4s into it.

    . +hat does R-e!ect rom emp!oymentR sho4FPrint the comp!ete inormation rom ta"!e Remp!oymentR in t4o ormats7=irst9 print it in a 4ay that it sho4s a!! types and a!! data. (E.g EP'OLEE(>AE (6ary69 >U''9 6Ed4ards6)9 ....) Lou can do this "y dereerencing

    1

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    11/16

    (DE*E=) the t4o co!umns o emp!oyment.-econd9 print it in a 4ay so that it on!y sho4s the data9 not the types.

    1

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    12/16

    . O"$ect%Based Data"aseW.

    [Refer Tutorial Week 5] Member Methods:

    1. 3reate 8LPE $o"#9 4hich contains the same co!umns as the type $o"(exercise #rom !ast 4ee,Xs exercises)9 "ut a!so inc!ude a methodReva!uateI5ua!iicationR to print Rtoo "adR or a!! $o"s that have !ess than # yearso experience9 ROR or # years o experience and RgreatR or more than t4o yearso experience.

    #. Add a second method to the type dec!aration o $o"#. 8his method is ca!!edsa!aryIraction. t ta,es a rea! num"er > as an argument and returns the sa!arydivided "y >. =or examp!e9 i > is 1#9 it returns the month!y sa!ary.

    &. 3reate an o"$ect ta"!e or $o"# and insert three ro4s.+rite an -' statement that se!ects eva!uateI5ua!iication and month!y sa!ariesor a!! ro4s o the ta"!e.+rite an -' statement that se!ects a!! co!umns or ro4s 4hich have an 6O6va!ue or eva!uateI5ua!iication and a ha!%year!y sa!ary o more than 1

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    13/16

    6a"c6

    /re/6c"3e "c/&$mer

    6

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    14/16

    2 SM. O'AP[Refer Tutorial Week 6_7]

    mp!ement the o!!o4ing mu!tidimensiona! star schema7@/ct T/e,

    -a!es(pid7 integer9 timeid integer9 !ocid integer9sa!es rea!)D%me&s%"& T/es,

    'ocations(!ocid integer9 city7 string9 state7 string9country7 string);Products(pid integer9pname string9 category string9 price7 rea!);8imes(timeid integer9 date7 string9 4ee,7 integer9 month7 integer9 5uarter7 integer9 year7integer9 ho!iday7 "oo!ean)

    3onsider the instance o -a!es re!ation1. -ho4 the resu!t o pivoting the re!ation on pid and timeid#. +rite a co!!ection o s5! 5ueries to o"tain the same resu!t as in the previous part&. -ho4 the resu!t o pivoting the re!ation on pid and !ocid

    3onsider the 3ross%ta"u!ation on -a!es "y year and state0. -ho4 the resu!t o ro!!%up on !ocid. +rite a co!!ection o s5! 5ueries to o"tain the same resu!t as in the previous part2. -ho4 the resu!t o ro!!%up on !ocid o!!o4ed "y dri!!%do4n on pidM. -ho4 the resu!t o ro!!%up on pid o!!o4ed "y dri!!%do4n on timeid

    3onsider the 'ocations9 Products9 and -a!es re!ationsN. =ind the percentage change in the tota! month!y sa!es or each !ocation

    . =ind the percentage change in the tota! month!y sa!es or each product1

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    15/16

    N. '

    [Refer Tutorial Week 8]

    1.3onsider a ail orderdata"ase in 4hich emp!oyees ta,e orders or parts romcustomers.

    8he data re5uirements are summari:ed as o!!o4s7

    8he mai! order company has emp!oyees identiied "y a uni5ue emp!oyee

    num"er9 their irst and !ast names9 and a :ip code 4here they are !ocated.

    3ustomers o the company are uni5ue!y identiied "y a customer num"er. n

    addition9 their irst and !ast names and a :ip code 4here they are !ocated arerecorded.

    8he parts "eing so!d "y the company are identiied "y a uni5ue part num"er.

    n addirion9 a part name9 their price9 and 5uantity in stoc, are recorded.

    Orders p!aced "y customers are ta,en "y emp!oyees and are given a uni5ue

    order num"er. Each order may contain certain 5uantities o one or more parts

    and their received date as 4e!! as a shipped date is recorded.a. 3reate a ' representation o the data (you shou!d invent your o4n data

    instances).". +rite a D8D / ' -chema speciication or the ' document

    constructed in part a.c. +rite expressions in uery to ans4er o!!o4ing 5ueries7

    i. *etrieve the names o parts that cost !ess than K#

  • 8/11/2019 Cse 532 Adbms Labmanual 2014 (1)

    16/16

    term9 ina! exam9 pro$ect9 etc.). Each grading component has a maximumnum"er o points (such as 1