learn db2 in an easy steps

Upload: melissa-miller

Post on 02-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Learn DB2 in an Easy Steps

    1/9

    Q. What is DB2? How does it compare with VSAM Files?

    DB2 is the Data-Management System from IBM. DB2 is a newer technology,whilstVSAM is old. VSAM(which stands for Virtual Seuential Access MethoaData Access-Method. #ou can $rowse a VSAM Dataset in Seuential Mode %record. #ou can do random access % "um'(ho'!, fly directly to a 'articul

    &ecord . Si'-Seuential is lie the $est of $oth worlds % )um' to *st rethen start $rowsing the su$seuent records one-$y-one. Sounds cool, ain+t

    hold on and hae a loo at what DB2 Software offers

    DB2 is a com'lete Software acage, that allows you to create, store, u'retriee Data in a Systematic Manner.

    *. Data A$straction / It 'resents a 0ogical, Structured iew of the Data1ser. he user doesn3t need to worry a$out the details of how the Data ishysically stored on the DASD-Dis.2. Data Inde'endence / DB2 'roides a layer of Inde'endence, $etween thea''lication or 45B50 rogram and the Data. 6ery-time the structure of tchanges(say you add a new field to the 6M05#66 7ile!, you don3t need re-entire 45B50 Source code again.

    8. Data Security / DB2 Software controls the Access to the Data. 9ot eesee all the Data. #ou can see it, only if you+e got all the necessary ':. ransaction Management and 4oncurrency / DB2 Manages all the ransactiensures the Data remains consistent. It 'roides a 0ocing-Mechanism, foconcurrent access to the Data.;. Data &ecoery /

  • 8/10/2019 Learn DB2 in an Easy Steps

    2/9

    he information a$out all the S5=&51+s(Storage =rou's! is stored in the4atalog a$le S#SIBM.S#SS5=&51. he sna'shot of all the S5=&51+s is sthe 'icture $elow.

    Data$ase / A Data$ase is a 0ogical-=rou'ing of Data$ase 5$"ects, related$y a''lication, or su$system. A Data$ase contains no Data of its own, $utgrou's lie DB2 5$"ects. o create a 9ew Data$ase, use the 4&6A6DAABAS6 Statement. In the e>am'le $elow, I hae created a 9ew Data$asecalledDS9?=?*A on the S5=&51 DS9?=?*@.

    The information on all the Databases in DB2 System is stored in the DB2 Catalog Table SYSIBM.SY

    http://lh5.ggpht.com/_sQvdFWqMlMg/TLr7j42j3wI/AAAAAAAADTQ/OGazorw2fac/s1600-h/Image324%5B4%5D.pnghttp://lh3.ggpht.com/_sQvdFWqMlMg/TLr7fL7Yk0I/AAAAAAAADTI/LwFPJn6WWus/s1600-h/Image323%5B5%5D.pnghttp://lh4.ggpht.com/_sQvdFWqMlMg/TLr7ZkSf2qI/AAAAAAAADTA/CQATyBVTz4o/s1600-h/Image322%5B4%5D.png
  • 8/10/2019 Learn DB2 in an Easy Steps

    3/9

    The below pit!re is a snapshot of it.

    Table"spae # A Table"Spae is a $SAM %ile whih stores or ho!ses the DB2 Table"Data &hysially.a Brand"'ew Table"spae %ile( by !sing the C)EATE TAB*ES&ACE Statement.

    In the pit!re abo+e( I ha+e reated a new Table"spae %ile alled DS',-,TS( whih has a &rimar//0B and Seondary Spae of //0B. 1!st lie the ontents in a Boo( the data in a Table"Spaein %i3ed"Si4e &ages. DS',-,TS Table"Spae is reated !nder the DS',-,5A Database 6mbrella. TSpae %ile will be stored on DS',-,5/ Storage"-ro!p. A b!ffer"pool is the plae in Main Storage(will store &ages fethed from the Table"Spae.

    http://lh6.ggpht.com/_sQvdFWqMlMg/TLr7su2xL9I/AAAAAAAADTg/niHSmHvOuSk/s1600-h/Image326%5B4%5D.pnghttp://lh6.ggpht.com/_sQvdFWqMlMg/TLr7oJCfWiI/AAAAAAAADTY/GyPbwoY6o0M/s1600-h/Image325%5B6%5D.png
  • 8/10/2019 Learn DB2 in an Easy Steps

    4/9

    The information abo!t all Table"Spae %iles is stored in the DB2 Catalog Table SYSIBM.SYSTAB*ESsnapshot of this is shown in the abo+e pit!re.

    7ne the Table"Spae %ile has been newly reated( yo! an at!ally see it !sing DS*IST 6tility in8.. The $SAM Dataset"name has the format +at.DS'DBC.dbname.tsname.9.

    Q. What are Tables !rimar" #e"s a$d Forei%$ #e"s?

    A a$le stores Data. a$les loo lie a s'readsheet, they consist of &ows4olumns, as shown in the 'icture $elow.

    he 6m'loyee-ID 9um$er is uniue for each 6m'loyee. 9o two 6m'loyees haesame 6m'loyee-ID in the 4om'any. Similarly, the De'artment-ID is uniue

    De'artment. 6m'loyee-ID 4olumn is said to $e the rimary-ey or

    rimary-Inde> in the 6M05#66 a$le. De'artment-ID is said to $e the riey or rimary-Inde> in the D6A&M69 a$le.

    Su''ose you want to esta$lish a &elationshi', and store the informationwhich 6m'loyee wors for which De'artment he 6M05#66 a$le should $e eand an additional column is added to it, called 7CD6CID. 6M05#66.7C4olumn refers to D6A&M69CID rimary-ey column of the D6A&M69 a$le7CD6CID is called 7oreign-ey. ere, is how it wors. &A) has 7CD60oo-u' De'artment-9o *@ in the D6A&M69 a$le, and it is the & De'artmeans &AM wors in & De'artment.

    http://lh3.ggpht.com/_sQvdFWqMlMg/TLr7-fQnpjI/AAAAAAAADUA/04I7kB9oDE4/s1600-h/Image331%5B2%5D.pnghttp://lh5.ggpht.com/_sQvdFWqMlMg/TLr75l5oELI/AAAAAAAADT4/7CgUTrOJER8/s1600-h/Image330%5B5%5D.pnghttp://lh6.ggpht.com/_sQvdFWqMlMg/TLr71nrVUdI/AAAAAAAADTw/KkYughDZy4w/s1600-h/Image328%5B4%5D.pnghttp://lh5.ggpht.com/_sQvdFWqMlMg/TLr7xXNRzyI/AAAAAAAADTo/RW_gflI-nOA/s1600-h/Image327%5B4%5D.png
  • 8/10/2019 Learn DB2 in an Easy Steps

    5/9

    Q. How do "ou write the DD& to create Tables a$d '$de( #e")*olum$s?

    As an e>am'le, let us $uild a toy Data$ase-System, called 9ew Businessracing(9B!, which stores the information a$out new Insurance olicies(Business! of an Agent for the first F@ days. his Data$ase System will hDB2 a$les % 459&A4, A=69C459C490 and I9S1&6D.

    459&A4 a$le Schemahe 459&A4 a$le stores the $asic Details of the 4ontract, what is the9o,how many Insured+s does this 4ontract coer(IS&DC59C459C49!, is itAnnuity olicy(0I96C57CB1SCD6S4!, when the A''lication was receied, wheolicy under-written, when the olicy got Issued, what is the 7ace AmountAssured! and many other details.

    DD0 7or 459&A4 a$le

    #ou write the 4&6A6 AB06 Statement listing all the 4olumns followed $yty'es, along with whether the 4olumn acce'ts 9100 Values or is it 95 910ist of 4olumns is a 4omma-Se'arated 0ist.

    http://lh4.ggpht.com/_sQvdFWqMlMg/TLr8PNq1R7I/AAAAAAAADUY/S3xagYlovPM/s1600-h/Image329%5B5%5D.pnghttp://lh6.ggpht.com/_sQvdFWqMlMg/TLr8JPIj86I/AAAAAAAADUQ/KpzBqxnL65Y/s1600-h/Image331%5B3%5D%5B2%5D.pnghttp://lh5.ggpht.com/_sQvdFWqMlMg/TLr8DiKANoI/AAAAAAAADUI/Y9N-73XJc0Q/s1600-h/Image332%5B2%5D.png
  • 8/10/2019 Learn DB2 in an Easy Steps

    6/9

    rimary Inde> 7or 459&A4 a$leere+s, how I hae created the rimary-Inde> on the 459&A4C95, 4AS6C9of the 459&A4 a$le. I hae created a 19IG16 I9D6H on the 459&A4 a$l

    A=69C459C490 a$le SchemaA=69C459C490 a$le stores the $asic data a$out the Insurance Agent, aInsurance olicies sold $y him.

    http://lh4.ggpht.com/_sQvdFWqMlMg/TLsmf1ZB1EI/AAAAAAAADVA/iSkwig_FqFo/s1600-h/Image337%5B4%5D.pnghttp://lh3.ggpht.com/_sQvdFWqMlMg/TLr8V6tZwrI/AAAAAAAADUg/uBj_mHU5vUA/s1600-h/Image333%5B5%5D.png
  • 8/10/2019 Learn DB2 in an Easy Steps

    7/9

    DD0 7or A=69C459C490 a$lehe A=69C459C490 a$le stores Agent Details. ow do you now, which o$elongs to which Agent-ID 7or each Agent, the olicy-9o sold $y him is s

    7C459&A4C95 4olumn, and this refers to the 459&A4C95 4olumn in 459Similarly, 7C4AS6C95 refers to the 4AS6C95 in the 459&A4 a$le. hus,

    foreign-ey(7C459&A4C95,7C4AS6C95! refers to therimary-ey(459&A4C95,4AS6C95! in the 459&A4 a$le. 5ne needs to undethat you cannot create a 7oreign-ey without defining a 19IG16 I9D6H.

    rimary Inde> 7or A=69C459C490 a$leI hae created a 9ew 1niue-Inde> IHCA=69C459C490 on the columns 7C47C4AS6C95 and A=69C45D6 of the A=69C459C490 a$le.

    http://lh3.ggpht.com/_sQvdFWqMlMg/TLsLenwlg5I/AAAAAAAADU4/ETfq3VQdKdQ/s1600-h/Image336%5B5%5D.pnghttp://lh4.ggpht.com/_sQvdFWqMlMg/TLsLbnbWQQI/AAAAAAAADUw/kFiDAbwAuCQ/s1600-h/Image335%5B3%5D.png
  • 8/10/2019 Learn DB2 in an Easy Steps

    8/9

    I9S1&6D a$le SchemaI9S1&6D a$le stores information a$out the Insured, or olicy-older. Ia )oin-olicy, a 4ontract may hae two or three Insured+s. In that case,Insured for that olicy has a different IS&DCS6GC95. he Insured+s 9ame,

    Birth etc. is stored in this a$le.

    DD0 7or I9S1&6D a$lehe 4&6A6 AB06 Statement for the I9S1&6D a$le is shown in the 'icture

    do you now, who is the olicy-older for a 'articular 4ontract-9o hisinformation is stored in the 4olumns 7C459&A4C95 and 7C4AS6C95, whic7oreign-ey, and refers to the corres'onding columns in the 459&A4 a$l

    http://lh3.ggpht.com/_sQvdFWqMlMg/TLsnH3LAXFI/AAAAAAAADVQ/-HTqp_wV9Ls/s1600-h/Image339%5B2%5D.pnghttp://lh3.ggpht.com/_sQvdFWqMlMg/TLsmojDNdoI/AAAAAAAADVI/Wpu_ZfqiGoc/s1600-h/Image338%5B5%5D.png
  • 8/10/2019 Learn DB2 in an Easy Steps

    9/9

    rimary Inde> 7or I9S1&6D a$leI hae created a rimary 1niue-Inde> on the IS&DCS6GC95,7C459&A4C957C4AS6C95 4olumns of the I9S1&6D a$le.

    http://lh4.ggpht.com/_sQvdFWqMlMg/TLsvwhvWGUI/AAAAAAAADVg/GVFKTrCjVh4/s1600-h/Image341%5B5%5D.pnghttp://lh3.ggpht.com/_sQvdFWqMlMg/TLsvrSdyvpI/AAAAAAAADVY/pH4pX_63wkw/s1600-h/Image340%5B5%5D.png