DB2 Version 9.1 for z/OS
Application Programming and SQL Guide
DB2 Version 9.1 for z/OS
Application Programming and SQL Guide
Note
Beforeusingthisinformationandtheproductitsupports,besuretoreadthegeneralinformationunder“Notices”onpage 1287.
First Edition (March 2007)
ThiseditionappliestoDB2Version9.1forz/OS(DB2V9.1forz/OS),productnumber5635-DB2,andtoany subsequentreleasesuntilotherwiseindicatedinneweditions.Makesureyouareusingthecorrecteditionforthe leveloftheproduct.
Specificchangesareindicatedbyaverticalbartotheleftofachange.Averticalbartotheleftofafigurecaption indicatesthatthefigurehaschanged.Editorialchangesthathavenotechnicalsignificancearenotnoted.
©CopyrightInternationalBusinessMachinesCorporation1983,2007.Allrightsreserved.
USGovernmentUsersRestrictedRights–Use,duplicationordisclosurerestrictedbyGSAADPScheduleContract
Contents
Aboutthis book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Whoshouldreadthisbook . . . xxi
Terminologyandcitations . . . xxi
Howtoreadthesyntaxdiagrams . . . xxii
AccessibilityfeaturesforDB2Version9.1forz/OS . . . xxiii
Accessibilityfeatures . . . xxiii
Keyboardnavigation . . . xxiii
Relatedaccessibilityinformation. . . xxiv
IBMandaccessibility . . . xxiv
Howtosendyourcomments. . . xxiv
Summaryofchanges tothisbook . . . . . . . . . . . . . . . . . . . . . . . xxv
Applicationand SQLreleaseincompatibilities. . . . . . . . . . . . . . . . . . xxvii
AdjustapplicationsthatdependonerrorinformationreturnedfromDB2-suppliedstoredproceduresand user-definedfunctions . . . xxvii
Qualifyuser-definedfunctionnames . . . xxvii
Fullydefineobjects . . . xxvii
SQLreservedwords . . . xxvii
ChangestoPL/IapplicationswithnoDECLAREVARIABLEstatements . . . xxvii
ChangesinBINDPACKAGEandBINDPLANdefaults . . . xxviii
PlansandpackagesboundonDB2Version3andbefore . . . xxviii
ChangedbehavioroftheINSERTstatementwiththeOVERRIDINGUSERVALUESclause . . . xxviii
DESCRIBEnolongerreturnsLONGtypevalues . . . xxviii
DB2enforcestherestrictionsaboutwhereahostvariablearraycanbespecified . . . xxviii
DEBUGSESSIONsystemprivilegerequiredforcontinueddebuggingofSQLprocedures . . . xxix
ChangestotheresultlengthoftheDECRYPTfunction . . . xxix
COLTYPEcolumninSYSIBM.SYSCOLUMNSandSYSIBM.SYSCOLUMNS_HISTforLONGcolumntypes . . . xxix
CREATEDBYcolumninSYSIBM.SYSDATATYPES,SYSIBM.SYSROUTINES,SYSIBM.SYSSEQUENCES,and SYSIBM.SYSTRIGGERS. . . xxix
DB2returnsallDSNWZPoutputinthesameformatasDB2parameters . . . xxix
DB2enforcestherestrictionthatrowIDsarenotcompatiblewithcharacterstringswhentheyareusedwithaset operator . . . xxx
YoucannolongerexplicitlycreateadatabasenameasDSNxxxxx . . . xxx
DatabaseprivilegesontheDSNDB04databasenowgiveyouthoseprivilegesonallimplicitly-createddatabases xxx Implicitly-createdobjectsthatareassociatedwithLOBcolumnsrequireadditionalprivileges . . . xxx
AdjustapplicationstouseLRHCLRinsteadofLGDISCLR . . . xxx
ChangedbehaviorfortheCREATEstatement . . . xxx
TheDECLAREstatementandtheworkfiledatabase . . . xxx
PlanfortheXMLdatatype . . . xxxi
ChangestoXMLNAMESPACES . . . xxxi
Changestoserializationofemptyelements . . . xxxi
AdjustmonitorprogramsthataccessOPbuffers . . . xxxi
Changedbehaviorforsystem-requiredobjects . . . xxxi
ChangestoINSERT,UPDATE,orDELETEstatementsonsomeindexes . . . xxxii
AvailabilityofLOBorXMLvaluesinJDBCorSQLJapplicationswithprogressivestreaming . . . xxxiii
LOBswithamaximumlengthgreaterthan1GBcannowbelogged . . . xxxiii
DB2returnsanerrorwhenaLOBvalueisspecifiedforanargumenttoastoredprocedureandtheargument valueislongerthanthetargetparameterandtheexcessisnottrailingblanks . . . xxxiii
ChangestoVARCHARfunctionformattingofdecimaldata . . . xxxiii
DB2dropscertainindexeswhenauniqueconstraintisdropped . . . xxxiii
Changestotheupperlimittothesizeoftherowthatisusedbysorttoevaluatecolumnfunctions. . . xxxiii
DB2enforcesrestrictiononspecifyingaCASTFROMclauseforsomeformsofCREATEFUNCTION statements. . . xxxiv
DB2enforcesrestrictionsonspecifyingtheASLOCATORclauseandTABLELIKEclause . . . xxxiv
|
||
||
||
||
||
||
||
||
||
||
||
||
||
|
||
||
|
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
|
||
||
||
||
|
||
||
DB2enforcesrestrictionontheCCSIDparameterfortheDECRYPT_BITandDECRYPT_BINARYfunctions xxxiv
ChangedbehaviorofCREATEPROCEDUREforanSQLprocedure . . . xxxiv
Resolutionofparameternames,variablenamesandcolumnnamesinSQLprocedures . . . xxxv
ChangedmessagesfromSQLprocedures . . . xxxv
Part 1. SQL queries
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter1.Retrievingdataby usingtheSELECT statement . . . . . . . . . . . . . 3
Resulttables . . . 3
Datatypes . . . 4
Selectingcolumns:SELECT . . . 6
Selectingallcolumns:SELECT* . . . 6
Selectingsomecolumns:SELECTcolumn-name . . . 7
Selectingderivedcolumns:SELECTexpression . . . 7
SelectingXMLdata . . . 8
Eliminatingredundantduplicaterows:DISTINCT. . . 8
Namingresultcolumns:AS . . . 9
Selectingrowsusingsearchconditions:WHERE . . . 10
CheckingwhetheranXMLcolumncontainsacertainvalue . . . 11
Puttingtherowsinorder:ORDERBY . . . 12
SpecifyingthesortkeyintheORDERBYclause . . . 12
ReferencingderivedcolumnsintheORDERBYclause . . . 13
Returningfullselectresultsintheorderofthesubqueryresulttable . . . 13
Summarizinggroupvalues:GROUPBY . . . 14
Subjectinggroupstoconditions:HAVING . . . 14
CombiningresulttablesfrommultipleSELECTstatements:UNION,EXCEPT,andINTERSECT . . . 15
Eliminatingredundantduplicaterowswhencombiningresulttables . . . 17
Keepingallduplicaterowswhencombiningresulttables . . . 18
Findingtherowsthatwerechangedwithinaspecifiedperiodoftime. . . 20
Determiningwhenarowwaschanged . . . 20
Rankingtherows:RANKandDENSE_RANK. . . 21
Numberingtherowsinaresulttable:ROW_NUMBER. . . 23
Commontableexpressions:WITH. . . 24
Usingcommontableexpressionsinsteadofviews . . . 24
Usingcommontableexpressionswithviews . . . 25
UsingcommontableexpressionswhenyouuseINSERT . . . 25
RecursiveSQL . . . 25
DB2datathatisnotinatable . . . 26
Precisionforoperationswithdecimalnumbers . . . 26
Avoidingdecimalarithmeticerrors . . . 27
ControllinghowDB2roundsdecimalfloatingpointnumbers . . . 28
FindinginformationintheDB2catalog . . . 28
Displayingalistoftablesthatyoucanuse . . . 28
Displayingalistofcolumnsinatable . . . 28
Chapter2.WorkingwithDB2 tablesandmodifying data . . . . . . . . . . . . . . 31
Workingwithtables . . . 31
Creatingyourowntables:CREATETABLE. . . 31
Temporarytables . . . 33
Droppingtables:DROPTABLE. . . 37
Workingwithviews . . . 37
Definingaview:CREATEVIEW . . . 37
Restrictionswhenchangingdatathroughaview . . . 39
Droppingviews:DROPVIEW . . . 39
ModifyingDB2data . . . 39
Insertingrows:INSERT . . . 39
Updatingcurrentvalues:UPDATE . . . 44
Updatingexistingdataandinsertingnewdata:MERGE . . . 45
Deletingrows:DELETEandTRUNCATE . . . 46
SelectingmodifiedDB2data. . . 47
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
Selectingvaluesasyouinsert:SELECTfromINSERT . . . 47
Selectingvaluesasyouupdate:SELECTFROMUPDATE . . . 53
Selectingvaluesasyoumerge:SELECTFROMMERGE . . . 53
Selectingvaluesasyoudelete:SELECTFROMDELETE . . . 55
Chapter3.Howtojoin datafrommore thanone DB2table . . . . . . . . . . . . . 57
Sampledataforjoins . . . 57
Innerjoin . . . 57
Outerjoin . . . 59
Fullouterjoin . . . 60
Leftouterjoin . . . 61
Rightouterjoin . . . 62
SQLrulesforstatementscontainingjoinoperations . . . 63
Joiningmorethantwotables . . . 64
Joiningmorethantwotablesbyusingmorethanonejointype . . . 64
Nestedtableexpressionsanduser-definedtablefunctionsinjoins . . . 65
Correlatedreferencesintablespecificationsinjoins . . . 67
Chapter4.Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Conceptualoverviewofsubqueries . . . 69
Correlatedanduncorrelatedsubqueries . . . 70
Subqueriesandpredicates . . . 70
Thesubqueryresulttable. . . 71
Howtocodeasubquery . . . 71
Basicpredicateinasubquery . . . 71
Quantifiedpredicateinasubquery:ALL,ANY,orSOME . . . 71
INpredicateinasubquery . . . 72
EXISTSpredicateinasubquery . . . 72
Correlatedsubqueries . . . 73
Anexampleofacorrelatedsubquery. . . 73
Correlationnamesinreferences. . . 74
UsingcorrelatedsubqueriesinanUPDATEstatement . . . 75
UsingcorrelatedsubqueriesinaDELETEstatement. . . 75
Chapter5.ExecutingSQLby usingSPUFI . . . . . . . . . . . . . . . . . . . . 79
OpeningSPUFIandspecifyinginitialoptions . . . 79
TheSPUFIpanel . . . 80
ChangingSPUFIdefaults. . . 82
CURRENTSPUFIDEFAULTSpanel . . . 84
CURRENTSPUFIDEFAULTS-PANEL2panel . . . 87
EnteringSQLstatementsinSPUFI. . . 88
UnicodeUTF-16graphicdatainSPUFI . . . 89
CommentsinSPUFI . . . 89
SettingtheSQLterminatorcharacterinaSPUFIinputdataset . . . 89
ControllingtolerationofwarningsinSPUFI . . . 90
ProcessingSQLstatementswithSPUFI . . . 91
SQLstatementsthatexceedresourcelimitthresholds . . . 91
OutputfromSPUFI. . . 93
FormattingrulesforSELECTstatementresultsinSPUFI . . . 93
ContentofthemessagesfromSPUFI . . . 94
Part 2. Coding SQL in your host application program
. . . . . . . . . . . . . 95
Chapter6.Basicsofcoding SQLinan applicationprogram. . . . . . . . . . . . . 99
ConventionsusedinexamplesofcodingSQLstatements. . . 100
DelimitinganSQLstatement . . . 100
Declaringtableandviewdefinitions. . . 101
Accessingdatausinghostvariables,hostvariablearrays,andstructures . . . 101
UsinghostvariablesinanSQLstatement . . . 102
||
||
||
HostvariablearraysinanSQLstatement . . . 108
UsinghoststructuresinanSQLstatement. . . 112
CheckingtheexecutionofSQLstatements. . . 113
UsingtheSQLcommunicationarea(SQLCA). . . 114
SQLCODEandSQLSTATE . . . 114
TheWHENEVERstatement . . . 115
Handlingarithmeticorconversionerrors . . . 116
TheGETDIAGNOSTICSstatement . . . 116
CallingDSNTIARtodisplaySQLCAfields . . . 121
Chapter7.Usinga cursortoretrieve a setofrows . . . . . . . . . . . . . . . . 125
Accessingdatabyusingarow-positionedcursor . . . 125
Step1:Declarethecursor . . . 125
Step2:Openthecursor . . . 127
Step3:Specifywhattodoatend-of-data . . . 128
Step4:ExecuteSQLstatements . . . 128
Step5:Closethecursor . . . 130
Accessingdatabyusingarowset-positionedcursor . . . 130
Step1:Declaretherowsetcursor. . . 130
Step2:Opentherowsetcursor . . . 131
Step3:Specifywhattodoatend-of-dataforarowsetcursor . . . 131
Step4:ExecuteSQLstatementswitharowsetcursor . . . 131
Step5:Closetherowsetcursor . . . 135
AccessingXMLandLOBdatausingFETCHWITHCONTINUE . . . 135
FETCHWITHCONTINUEusingdynamicbufferallocation. . . 136
FETCHWITHCONTINUEusingfixedbufferallocation . . . 136
Typesofcursors . . . 138
Scrollableandnon-scrollablecursors . . . 138
Heldandnon-heldcursors . . . 147
Examplesofusingcursors . . . 149
Chapter8.Generatingdeclarations foryourtablesusing DCLGEN . . . . . . . . . 155
InvokingDCLGENthroughDB2I . . . 156
Includingthedatadeclarationsinyourprogram . . . 159
DCLGENsupportofC,COBOL,andPL/Ilanguages . . . 160
Example:Addingatabledeclarationandhost-variablestructuretoalibrary . . . 161
Step1.SpecifyCOBOLasthehostlanguage . . . 161
Step2.Createthetabledeclarationandhoststructure. . . 162
Step3.Examinetheresults. . . 164
Chapter9.EmbeddingSQLstatementsinhost languages . . . . . . . . . . . . . 167
CodingSQLstatementsinanassemblerapplication . . . 167
DefiningtheSQLcommunicationsareainassembler . . . 167
DefiningSQLdescriptorareasinassembler . . . 168
EmbeddingSQLstatementsinassembler . . . 169
Hostvariablesinassembler . . . 171
Declaringhostvariablesinassembler . . . 171
EquivalentSQLandassemblerdatatypes . . . 175
CompatibilityofSQLandassemblerdatatypes . . . 181
Indicatorvariablesinassembler . . . 182
HandlingSQLerrorreturncodesinassembler . . . 183
Macrosforassemblerapplications . . . 184
CodingSQLstatementsinaCorC++application . . . 185
DefiningtheSQLcommunicationareainCorC++. . . 185
DefiningSQLdescriptorareasinCorC++ . . . 186
EmbeddingSQLstatementsinCorC++ . . . 186
HostvariablesandhostvariablearraysinCorC++ . . . 188
DeclaringhostvariablesinCorC++ . . . 190
DeclaringhostvariablearraysinCorC++ . . . 199
HoststructuresinCorC++ . . . 206
||
||
||
EquivalentSQLandCdatatypes. . . 208
CompatibilityofSQLandCdatatypes. . . 215
IndicatorvariablesandindicatorvariablearraysinCorC++ . . . 217
HandlingSQLerrorreturncodesinCorC++ . . . 218
CodingSQLstatementsinaCOBOLapplication. . . 220
DefiningtheSQLcommunicationareainCOBOL . . . 220
DefiningSQLdescriptorareasinCOBOL . . . 221
EmbeddingSQLstatementsinCOBOL. . . 222
HostvariablesandhostvariablearraysinCOBOL . . . 226
DeclaringhostvariablesinCOBOL . . . 226
DeclaringhostvariablearraysinCOBOL . . . 234
HoststructuresinCOBOL . . . 242
EquivalentSQLandCOBOLdatatypes . . . 247
CompatibilityofSQLandCOBOLdatatypes. . . 254
IndicatorvariablesandindicatorvariablearraysinCOBOL . . . 255
HandlingSQLerrorreturncodesinCOBOL . . . 257
Object-orientedextensionsinCOBOL . . . 258
CodingSQLstatementsinaFortranapplication. . . 259
DefiningtheSQLcommunicationareainFortran . . . 259
DefiningSQLdescriptorareasinFortran . . . 260
EmbeddingSQLstatementsinFortran . . . 260
HostvariablesinFortran . . . 262
DeclaringhostvariablesinFortran . . . 262
EquivalentSQLandFortrandatatypes. . . 264
CompatibilityofSQLandFortrandatatypes. . . 267
IndicatorvariablesinFortran . . . 267
HandlingSQLerrorreturncodesinFortran . . . 268
CodingSQLstatementsinaPL/Iapplication . . . 269
DefiningtheSQLcommunicationareainPL/I . . . 269
DefiningSQLdescriptorareasinPL/I . . . 270
EmbeddingSQLstatementsinPL/I. . . 270
HostvariablesandhostvariablearraysinPL/I . . . 273
DeclaringhostvariablesinPL/I . . . 273
DeclaringhostvariablearraysinPL/I . . . 278
HoststructuresinPL/I . . . 282
EquivalentSQLandPL/Idatatypes . . . 284
CompatibilityofSQLandPL/Idatatypes . . . 288
IndicatorvariablesandindicatorvariablearraysinPL/I . . . 290
HandlingSQLerrorreturncodesinPL/I . . . 291
CodingSQLstatementsinaREXXapplication . . . 293
DefiningtheSQLcommunicationareainREXX . . . 293
DefiningSQLdescriptorareasinREXX. . . 293
AccessingtheDB2REXXLanguageSupportapplicationprogramminginterfaces. . . 294
EmbeddingSQLstatementsinaREXXprocedure . . . 295
CursorsandstatementnamesinREXX. . . 297
REXXhostvariablesanddatatypes . . . 297
IndicatorvariablesinREXX . . . 301
SettingtheisolationlevelofSQLstatementsinaREXXprocedure. . . 302
Chapter10.Maintaining dataintegrity byusing constraints . . . . . . . . . . . . 303
Checkconstraints . . . 303
Checkconstraintconsiderations . . . 303
Whencheckconstraintsareenforced . . . 304
HowcheckconstraintssetCHECK-pendingstatus . . . 304
Referentialconstraints . . . 305
Parentkeycolumns . . . 305
Definingaparentkeyandauniqueindex. . . 306
Definingaforeignkey . . . 308
Referentialconstraintsontableswithmultilevelsecuritywithrow-levelgranularity. . . 310
Usinginformationalreferentialconstraints. . . 311
Chapter11.UsingDB2-generated values askeys . . . . . . . . . . . . . . . . . 313
ROWIDcolumnsaskeys . . . 313
DefiningaROWIDcolumn. . . 313
SpecifyingdirectrowaccessbyusingaROWIDcolumn . . . 314
SpecifyingdirectrowaccessbyusingRIDs . . . 314
Usingidentitycolumnsaskeys . . . 315
Defininganidentitycolumn . . . 315
Identitycolumnsasprimarykeys . . . 316
Usingvaluesobtainedfromsequenceobjectsaskeys . . . 317
Creatingasequenceobject . . . 318
Referencingasequenceobject . . . 318
Keysacrossmultipletables. . . 318
Chapter12.Usingtriggers foractive data . . . . . . . . . . . . . . . . . . . . 321
Exampleofcreatingandusingatrigger . . . 321
Partsofatrigger . . . 323
Triggername . . . 323
Subjecttable. . . 323
Triggeractivationtime . . . 323
Triggeringevent . . . 323
Granularity . . . 324
Transitionvariables . . . 325
Transitiontables . . . 326
Triggeredaction . . . 327
Invokingstoredproceduresanduser-definedfunctionsfromtriggers. . . 329
Passingtransitiontablestouser-definedfunctionsandstoredprocedures . . . 329
Triggercascading . . . 330
Orderingofmultipletriggers . . . 331
Inserting,updating,anddeletingdatainviewsbyusingINSTEADOFtriggers . . . 331
Interactionsbetweentriggersandreferentialconstraints . . . 333
Interactionsbetweentriggersandtablesthathavemultilevelsecuritywithrow-levelgranularity . . . 334
Creatingtriggerstoobtainconsistentresults . . . 335
Part 3. Using DB2 object-relational extensions
. . . . . . . . . . . . . . . . 339
Chapter13.IntroductiontoDB2 object-relational extensions . . . . . . . . . . . . 341
Chapter14.Programmingfor large objects . . . . . . . . . . . . . . . . . . . 343
IntroductiontoLOBs. . . 343
StoringLOBdatainatable. . . 343
ImplicitlyhiddenROWIDcolumns . . . 345
WaystomanipulateLOBdata. . . 345
LOBhostvariable,LOBlocator,andLOBfilereferencevariabledeclarations . . . 346
LOBmaterialization . . . 351
UsingLOBlocatorstosavestorage . . . 352
DeferringevaluationofaLOBexpressiontoimproveperformance . . . 352
IndicatorvariablesandLOBlocators . . . 354
ValidassignmentsforLOBlocators . . . 355
AvoidingcharacterconversionforLOBlocators . . . 355
LOBfilereferencevariables . . . 355
DB2-generatedfilereferencevariableconstructs . . . 356
Examplesofdeclaringfilereferencevariables. . . 357
Chapter15.User-definedfunctions . . . . . . . . . . . . . . . . . . . . . . . 359
Overviewofuser-definedfunctiondefinition,implementation,andinvocation . . . 359
Exampleofcreatingandusingauser-definedscalarfunction . . . 360
User-definedfunctionsamplesshippedwithDB2 . . . 361
Definingauser-definedfunction . . . 362
Componentsofauser-definedfunctiondefinition . . . 362
||
||
||
||
||
||
Examplesofuser-definedfunctiondefinitions . . . 364
Implementinganexternaluser-definedfunction. . . 367
Writingauser-definedfunction . . . 367
Preparingauser-definedfunctionforexecution . . . 400
Testingauser-definedfunction . . . 402
ImplementinganSQLscalarfunction . . . 404
Implementingasourcedfunction. . . 405
Invokingauser-definedfunction . . . 405
EnsuringthatDB2executestheintendeduser-definedfunction. . . 405
Castingofuser-definedfunctionarguments . . . 411
Whathappenswhenauser-definedfunctionabnormallyterminates . . . 413
NestingSQLstatements . . . 413
Recommendationsforinvokinguser-definedfunctions . . . 414
Chapter16.Creatingand usingdistincttypes . . . . . . . . . . . . . . . . . . 417
Introductiontodistincttypes . . . 417
Usingdistincttypesinapplicationprograms . . . 418
Comparingdistincttypes . . . 418
Assigningdistincttypes . . . 419
UsingdistincttypeswithUNION,EXCEPT,andINTERSECT . . . 421
Invokingfunctionswithdistincttypes . . . 421
Combiningdistincttypeswithuser-definedfunctionsandLOBs . . . 422
Chapter17.XMLdatainembedded SQLapplications . . . . . . . . . . . . . . . 427
HostvariabledatatypesforXMLdatainembeddedSQLapplications . . . 427
XMLcolumnupdatesinembeddedSQLapplications . . . 431
XMLdataretrievalinembeddedSQLapplications . . . 434
Part 4. Designing a DB2 database application
. . . . . . . . . . . . . . . . 437
Chapter18.PlanningforDB2 programpreparation . . . . . . . . . . . . . . . . 439
PlanningtoprocessSQLstatements . . . 441
Planningtobind . . . 442
BindingDBRMswithpackagesandplans . . . 442
Planningforchangestoyourapplication . . . 444
Chapter19.Planningforconcurrency. . . . . . . . . . . . . . . . . . . . . . 451
Definitionsofconcurrencyandlocks . . . 451
EffectsofDB2locks . . . 452
Suspension . . . 452
Timeout . . . 453
Deadlock. . . 453
Basicrecommendationstopromoteconcurrency. . . 455
Recommendationsfordatabasedesign . . . 456
Recommendationsforapplicationdesign . . . 457
Aspectsoftransactionlocks . . . 461
Thesizeofalock . . . 461
Thedurationofalock . . . 463
Themodeofalock . . . 464
Theobjectofalock . . . 466
Optionsfortuninglocks. . . 467
Bindoptions. . . 467
OverridingisolationlevelswithSQLstatements. . . 480
TheLOCKTABLEstatement . . . 481
Accesspaths . . . 482
TheSKIPLOCKEDDATAoption. . . 483
LOBlocks . . . 485
RelationshipbetweentransactionlocksandLOBlocks . . . 485
HierarchyofLOBlocks . . . 486
||
||
||
LOBandLOBtablespacelockmodes . . . 486
LOBlockandLOBtablespacelockduration . . . 486
InstanceswhenLOBtablespacelocksarenottaken . . . 487
TheLOCKTABLEstatementforLOBs . . . 487
XMLlocks . . . 488
LocksthatareacquiredforoperationsonXMLdata . . . 488
HierarchyofXMLlocks . . . 489
XMLandXMLtablespacelockmodes . . . 489
XMLlockandXMLtablespacelockduration . . . 490
InstanceswhenXMLtablespacelocksarenottaken . . . 490
TheLOCKTABLEstatementforXMLdata . . . 491
Chapter20.Planningforrestart and recovery . . . . . . . . . . . . . . . . . . 493
UnitofworkinTSObatchandonline . . . 494
UnitofworkinCICS. . . 494
UnitofworkinIMSonlineprograms . . . 495
Planningaheadforprogramrecovery:Checkpointandrestart . . . 497
Whenarecheckpointsimportant? . . . 498
CheckpointsinMPPsandtransaction-orientedBMPs . . . 498
Checkpointsinbatch-orientedBMPs . . . 499
Specifyingcheckpointfrequency . . . 500
UnitofworkinDL/IandIMSbatchprograms . . . 500
Commitandrollbackcoordination . . . 500
RestartandrecoveryinIMSbatch . . . 501
Usingsavepointstoundoselectedchangeswithinaunitofwork . . . 501
PlanningforrecoveryofNOTLOGGEDtablespaces . . . 503
Restartimplicationsfortablespacesthatarenotlogged . . . 503
Chapter21.Planningtoaccessdistributed data . . . . . . . . . . . . . . . . . 505
Planningforremoteaccess . . . 505
AdvantagesofDRDAaccess . . . 506
PreparingyoursystemforDRDAaccess . . . 506
TheprivatetoDRDAprotocolREXXtool(DSNTP2DP) . . . 508
Bindprocessesforremoteaccess . . . 513
PrecompilerandbindoptionsforDRDAaccess . . . 514
Codingmethodsfordistributeddata . . . 517
Usingthree-parttablenamestoaccessdistributeddata . . . 518
UsingexplicitCONNECTstatementstoaccessdistributeddata . . . 519
Coordinatingupdatestotwoormoredatasources . . . 521
Workingwithouttwo-phasecommit. . . 522
Updaterestrictionsonserversthatdonotsupporttwo-phasecommit . . . 522
ForcingupdaterestrictionsbyusingCONNECT(Type1). . . 523
Maximizingperformancefordistributeddata . . . 523
Codingefficientqueries . . . 523
MaximizingLOBperformanceinadistributedenvironment. . . 524
Usingbindoptionstoimproveperformancefordistributedapplications . . . 525
Usingblockfetchindistributedapplications . . . 528
LimitingthenumberofDRDAnetworktransmissions. . . 530
LimitingthenumberofrowsreturnedtoDRDAclients . . . 534
Workingwithdistributeddata. . . 535
SQLlimitationsatdissimilarservers. . . 535
ExecutinglongSQLstatementsinadistributedenvironment . . . 536
RetrievingdatafromASCIIorUnicodetables . . . 536
Accessingdatawithascrollablecursorwhentherequesterisdown-level . . . 537
Accessingdatawitharowset-positionedcursorwhentherequesterisdown-level . . . 537
Maintainingdatacurrencybyusingcursors . . . 537
Copyingatablefromaremotelocation. . . 537
Transmittingmixeddata. . . 537
Part 5. Developing your application
. . . . . . . . . . . . . . . . . . . . . 539
||
||
||
||
||
||
Chapter22.Preparingan applicationprogram torun . . . . . . . . . . . . . . . 541
SQLstatementprocessing . . . 541
CCSIDconversionofsourceprograms . . . 541
Stepsinprogrampreparation . . . 542
Step1:ProcessSQLstatements . . . 542
Step2:Compile(orassemble)andlink-edittheapplication . . . 560
Step3:Bindtheapplication . . . 561
Step4:Runtheapplication. . . 577
PreparingapplicationsbyusingJCLprocedures. . . 581
AvailableJCLprocedures . . . 582
IncludingcodefromSYSLIBdatasets . . . 583
Startingtheprecompilerdynamically . . . 583
AnalternativemethodforpreparingaCICSprogram . . . 585
Preparingaprogramwithobject-orientedextensionsbyusingJCL . . . 586
PreparingapplicationsbytheDB2ProgramPreparationpanels . . . 587
DB2IPrimaryOptionMenu . . . 587
DB2Ipanelsthatareusedforprogrampreparation. . . 589
DB2Ipanelsthatareusedtorebindandfreeplansandpackagesandtorunapplicationprograms. . . 616
TheRunpanel . . . 625
Chapter23.Testing anapplication program . . . . . . . . . . . . . . . . . . . 627
Establishingatestenvironment . . . 627
Designingatestdatastructure . . . 627
Fillingthetableswithtestdata . . . 630
MethodsfortestingSQLstatements . . . 630
Debuggingyourprogram . . . 631
DebuggingprogramsinTSO . . . 631
DebuggingprogramsinIMS . . . 631
DebuggingprogramsinCICS . . . 632
Locatingtheproblem. . . 636
Analyzingerrorandwarningmessagesfromtheprecompiler . . . 637
SYSTERMoutputfromtheprecompiler . . . 638
SYSPRINToutputfromtheprecompiler . . . 638
Chapter24.ProcessingDL/I batchapplications. . . . . . . . . . . . . . . . . . 643
PlanningtouseDL/Ibatchapplications . . . 643
FeaturesandfunctionsofDB2DL/Ibatchsupport. . . 643
RequirementsforusingDB2inaDL/Ibatchjob . . . 644
AuthorizationforusingDL/Ibatch . . . 644
ProgramdesignconsiderationsforusingDL/Ibatch . . . 644
AddressspacesinDL/Ibatch. . . 645
CommitsinDL/Ibatch . . . 645
SQLstatementsandIMScallsinDL/Ibatch . . . 645
CheckpointcallsinDL/Ibatch . . . 645
ApplicationprogramsynchronizationinDL/Ibatch . . . 645
CheckpointandXRSTconsiderationsinDL/Ibatch . . . 645
SynchronizationcallabendsinDL/Ibatch . . . 646
InputandoutputdatasetsforDL/Ibatchjobs . . . 646
DB2DL/Ibatchinput . . . 646
DB2DL/Ibatchoutput . . . 648
PreparationguidelinesforDL/Ibatchprograms . . . 648
Precompilingabatchprogram. . . 648
Bindingabatchprogram . . . 649
Link-editingabatchprogram . . . 649
Loadingandrunningabatchprogram . . . 649
Restartandrecoveryofabatchprogram . . . 651
JCLexampleofabatchbackout . . . 651
JCLexampleofrestartingaDL/Ibatchjob . . . 651
FindingtheDL/IbatchcheckpointID . . . 652
||
Part 6. Additional programming techniques
. . . . . . . . . . . . . . . . . 655
Chapter25.CodingdynamicSQLin applicationprograms . . . . . . . . . . . . . 661
ChoosingbetweenstaticanddynamicSQL . . . 661
FlexibilityofstaticSQLwithhostvariables . . . 662
FlexibilityofdynamicSQL . . . 662
LimitationsofdynamicSQL . . . 662
DynamicSQLprocessing . . . 662
PerformanceofstaticanddynamicSQL . . . 663
CachingdynamicSQLstatements . . . 665
Usingthedynamicstatementcache . . . 666
Usingthestatementcachetable . . . 667
Keepingpreparedstatementsaftercommitpoints . . . 668
LimitingdynamicSQLwiththeresourcelimitfacility . . . 670
Writinganapplicationtohandlereactivegoverning . . . 670
Writinganapplicationtohandlepredictivegoverning. . . 671
Usingpredictivegoverninganddown-levelDRDArequesters . . . 671
Usingpredictivegoverningandenabledrequesters. . . 671
ChoosingahostlanguagefordynamicSQLapplications . . . 671
DynamicSQLfornon-SELECTstatements. . . 672
DynamicexecutionusingEXECUTEIMMEDIATE . . . 672
DynamicexecutionusingPREPAREandEXECUTE . . . 674
Dynamicexecutionofadatachangestatementwithhostvariablearrays . . . 676
UsingDESCRIBEINPUTtoputparameterinformationinanSQLDA . . . 679
DynamicSQLforfixed-listSELECTstatements . . . 679
Declaringacursorforthestatementname. . . 680
Preparingthestatement . . . 680
Openingthecursor . . . 681
Fetchingrowsfromtheresulttable . . . 681
Closingthecursor. . . 681
DynamicSQLforvarying-listSELECTstatements . . . 681
Whatyourapplicationprogrammustdoforvarying-listSELECTstatements . . . 682
Preparingavarying-listSELECTstatement . . . 682
Executingavarying-listSELECTstatementdynamically . . . 694
Executingarbitrarystatementswithparametermarkers . . . 695
HowbindoptionsREOPT(ALWAYS),REOPT(AUTO)andREOPT(ONCE)affectdynamicSQL . . . 696
UsingdynamicSQLinCOBOL . . . 699
Chapter26.Stored proceduresforclient/server processing . . . . . . . . . . . . 701
Introductiontostoredprocedures . . . 701
Anexampleofasimplestoredprocedure . . . 703
ComparisonofanSQLprocedureandanexternalprocedure . . . 707
Settingupthestoredproceduresenvironment . . . 708
DefiningyourstoredproceduretoDB2. . . 709
Refreshingthestoredproceduresenvironment(forsystemadministrators) . . . 713
MovingstoredprocedurestoaWLM-establishedenvironment(forsystemadministrators) . . . 713
SQLprocedures . . . 714
CreatinganexternalSQLprocedure. . . 715
CreatinganativeSQLprocedure . . . 727
SQLprocedurebody . . . 731
IndicatorvariablesforSQLprocedures . . . 754
ExamplesofSQLprocedures . . . 755
Externalstoredprocedures . . . 757
Languagerequirementsfortheexternalstoredprocedureanditscaller . . . 757
Callingotherprogramswithanexternalstoredprocedure . . . 757
Reentrantcodeinexternalstoredprocedures. . . 758
Writinganexternalstoredprocedureasamainprogramorsubprogram . . . 758
Accessingothersitesinanexternalprocedure . . . 761
WritinganexternalproceduretoaccessIMSdatabases . . . 762
WritinganexternalproceduretoreturnresultsetstoaDRDAclient . . . 762
||
||
Preparinganexternalprocedure . . . 764
Bindinganexternalprocedure. . . 765
WritingaREXXstoredprocedure . . . 766
COMMITandROLLBACKstatementsinastoredprocedure . . . 769
Specialregistersinastoredprocedure . . . 770
Restrictionsforstoredprocedures . . . 770
Writingandpreparinganapplicationtousestoredprocedures. . . 771
FormsoftheCALLstatement . . . 771
Authorizationforexecutingstoredprocedures . . . 773
Parameterlistforstoredprocedures. . . 773
Usingindicatorvariablestospeedprocessing . . . 793
Declaringdatatypesforpassedparameters . . . 793
WritingaDB2forz/OSclientprogramorSQLproceduretoreceiveresultsets . . . 798
Accessingtransitiontablesinastoredprocedure . . . 804
CallingastoredprocedurefromaREXXprocedure . . . 804
Preparingaclientprogramforastoredprocedure . . . 808
Runningastoredprocedure . . . 809
HowDB2determineswhichstoredproceduretorun . . . 810
Usingasingleapplicationprogramtocalldifferentversionsofastoredprocedure . . . 810
Runningmultiplestoredproceduresconcurrently . . . 812
Multipleinstancesofastoredprocedure . . . 812
Accessingnon-DB2resourcesbyusingastoredprocedure . . . 813
Runningstoredproceduresfromthecommandlineprocessor . . . 814
Multipleversionsofstoredprocedures . . . 816
MultipleversionsofexternalproceduresandexternalSQLprocedures . . . 816
MultipleversionsofnativeSQLstoredprocedures . . . 816
Methodsfortestingastoredprocedure. . . 820
DebuggingwiththeDebugToolandIBMVisualAgeCOBOL . . . 821
DebuggingaClanguagestoredprocedurewiththeDebugToolandC/C++ProductivityToolsforz/OS . . 822
TheUnifiedDebugger . . . 823
DebuggingwithDebugToolforz/OSinteractivelyandinbatchmode . . . 823
UsingtheMSGFILErun-timeoptionfordebugging . . . 825
Driverapplicationsfordebuggingprocedures . . . 825
Howtoputdebugginginformationinatable . . . 825
Chapter27.Tuningyourqueries . . . . . . . . . . . . . . . . . . . . . . . . 827
Generaltipsandquestions . . . 827
Isthequerycodedassimplyaspossible? . . . 827
Areallpredicatescodedcorrectly? . . . 827
Doesyourqueryincludesubqueries? . . . 828
Doesyourqueryinvolveaggregatefunctions? . . . 829
DoyouhaveaninputvariableinthepredicateofanSQLquery? . . . 830
Doyouhaveaproblemwithcolumncorrelation? . . . 830
Canyourquerybewrittentouseanon-columnexpression? . . . 830
Canmaterializedquerytableshelpyourqueryperformance? . . . 831
Doesyourquerycontainencrypteddata? . . . 831
DoesyourquerycontainXMLdata?. . . 831
Writingefficientpredicates . . . 831
Propertiesofpredicates . . . 832
PredicatesintheONclause . . . 835
Generalrulesaboutpredicateevaluation . . . 835
Orderofevaluatingpredicates. . . 836
Summaryofpredicateprocessing. . . 836
Examplesofpredicateproperties . . . 842
Predicatefilterfactors . . . 843
Columncorrelation . . . 851
DB2predicatemanipulation . . . 855
Predicateswithencrypteddata . . . 858
Usinghostvariablesefficiently . . . 859
Changingtheaccesspathatruntime . . . 859
Rewritingqueriestoinfluenceaccesspathselection . . . 862
||
||
||
||
||
||
||
Writingefficientsubqueries. . . 865
Correlatedandnon-correlatedsubqueries . . . 865
ConditionsforDB2totransformasubqueryintoajoin . . . 866
SubqueriesthatDB2cannottransformtojoins . . . 868
Subquerytuning . . . 869
Usingscrollablecursorsefficiently . . . 870
Writingefficientqueriesontableswithdata-partitionedsecondaryindexes. . . 871
Specialtechniquestoinfluenceaccesspathselection . . . 874
Obtaininginformationaboutaccesspaths . . . 874
Fetchingalimitednumberofrows:FETCHFIRSTnROWSONLY . . . 875
Minimizingoverheadforretrievingfewrows:OPTIMIZEFORnROWS . . . 876
Favoringindexaccess . . . 878
UsingtheCARDINALITYclausetoimprovetheperformanceofquerieswithuser-definedtablefunction references . . . 878
Reducingthenumberofmatchingcolumns . . . 879
Creatingindexesforefficientstar-joinprocessing . . . 881
RearrangingtheorderoftablesinaFROMclause . . . 883
Updatingcatalogstatistics . . . 884
Usingasubsystemparameter . . . 885
Chapter28.UsingEXPLAIN toimprove SQLperformance . . . . . . . . . . . . . 889
ObtainingPLAN_TABLEinformationfromEXPLAIN . . . 890
CreatingPLAN_TABLE . . . 891
Populatingandmaintainingaplantable . . . 894
Reorderingrowsfromaplantable . . . 896
Askingquestionsaboutdataaccess . . . 896
Isaccessthroughanindex?(ACCESSTYPEisI,I1,N,MX,orDX) . . . 897
Isaccessthroughmorethanoneindex?(ACCESSTYPE=M) . . . 897
Howmanycolumnsoftheindexareusedinmatching?(MATCHCOLS=n) . . . 900
Isthequerysatisfiedusingonlytheindex?(INDEXONLY=Y) . . . 900
Isdirectrowaccesspossible?(PRIMARY_ACCESSTYPE=D) . . . 901
Isaviewornestedtableexpressionmaterialized? . . . 905
Wasascanlimitedtocertainpartitions?(PAGE_RANGE=Y) . . . 905
Whatkindofprefetchingisexpected?(PREFETCH=D,S,L,orblank) . . . 906
Isdataaccessedorprocessedinparallel?(PARALLELISM_MODEisI,C,orX) . . . 906
Aresortsperformed?. . . 906
Isasubquerytransformedintoajoin? . . . 907
Whenareaggregatefunctionsevaluated?(COLUMN_FN_EVAL) . . . 907
Howmanyindexscreeningcolumnsareused? . . . 908
IsacomplextriggerWHENclauseused?(QBLOCKTYPE=TRIGGR) . . . 908
IsaMERGEstatementused?(QBLOCK_TYPE=MERGE) . . . 908
Interpretingaccesstoasingletable . . . 909
Tablespacescans(ACCESSTYPE=RPREFETCH=S) . . . 909
Indexaccesspaths. . . 910
UPDATEusinganindex . . . 916
Interpretingaccesstotwoormoretables(join) . . . 916
Definitionsandexamplesofjoinoperations . . . 916
Nestedloopjoin(METHOD=1) . . . 918
Mergescanjoin(METHOD=2) . . . 921
Hybridjoin(METHOD=4) . . . 923
Starjoin(JOIN_TYPE=’S’) . . . 924
Interpretingaccessforsubqueries . . . 931
Non-correlatedsubqueries . . . 931
Correlatedsubqueries . . . 932
Interpretingdataprefetch . . . 932
Dynamicprefetch(PREFETCH=D) . . . 932
Sequentialprefetch(PREFETCH=S) . . . 934
Listprefetch(PREFETCH=L) . . . 934
Thenumberofpagesreadbyprefetch . . . 935
Determiningsortactivity . . . 936
Sortsofdata. . . 936
||
||
||
||
||
||
SortsofRIDs . . . 937
TheeffectofsortsonOPENCURSOR . . . 938
Processingforviewsandnestedtableexpressions . . . 938
Merge. . . 938
Materialization . . . 939
UsingEXPLAINtodeterminewhenmaterializationoccurs . . . 941
UsingEXPLAINtodetermineUNION,INTERSECT,andEXCEPTactivityandqueryrewrite . . . 942
Performanceofmergeversusmaterialization. . . 944
Estimatingastatement’scost . . . 945
Creatingastatementtable . . . 946
Populatingandmaintainingastatementtable . . . 946
Retrievingrowsfromastatementtable. . . 947
Theimplicationsofcostcategories . . . 947
Chapter29.Paralleloperations andquery performance . . . . . . . . . . . . . . 949
Comparingthemethodsofparallelism . . . 950
Enablingparallelprocessing . . . 952
Whenparallelismisnotused . . . 953
InterpretingEXPLAINoutput . . . 954
AmethodforexaminingPLAN_TABLEcolumnsforparallelism . . . 954
PLAN_TABLEexamplesshowingparallelism. . . 955
Tuningparallelprocessing . . . 956
Disablingqueryparallelism . . . 957
Chapter30.Programmingfor theInteractive SystemProductivityFacility . . . . . . 959
UsingISPFandtheDSNcommandprocessor . . . 959
InvokingasingleSQLprogramthroughISPFandDSN . . . 960
InvokingmultipleSQLprogramsthroughISPFandDSN. . . 961
InvokingmultipleSQLprogramsthroughISPFandCAF. . . 962
Chapter31.Programmingfor thecall attachmentfacility. . . . . . . . . . . . . . 963
CAFcapabilitiesandrequirements . . . 963
CAFcapabilities . . . 963
CAFrequirements. . . 965
HowtouseCAF . . . 966
Summaryofconnectionfunctions . . . 968
AccessingtheCAFlanguageinterface . . . 969
GeneralpropertiesofCAFconnections. . . 970
CAFfunctiondescriptions . . . 971
CONNECT:Syntaxandusage. . . 973
OPEN:Syntaxandusage . . . 977
CLOSE:Syntaxandusage . . . 979
DISCONNECT:Syntaxandusage . . . 980
TRANSLATE:Syntaxandusage . . . 982
SummaryofCAFbehavior. . . 983
Samplescenarios . . . 984
Asingletaskwithimplicitconnections. . . 984
Asingletaskwithexplicitconnections . . . 985
Severaltasks . . . 985
Exitroutinesfromyourapplication . . . 985
Attentionexitroutines . . . 985
Recoveryroutines . . . 986
Errormessagesanddsntrace . . . 986
CAFreturncodesandreasoncodes . . . 986
ProgramexamplesforCAF. . . 987
SampleJCLforusingCAF . . . 987
SampleassemblercodeforusingCAF . . . 988
LoadinganddeletingtheCAFlanguageinterface . . . 988
ConnectingtoDB2forCAF . . . 988
CheckingreturncodesandreasoncodesforCAF . . . 990
||
UsingdummyentrypointDSNHLIforCAF . . . 992
VariabledeclarationsforCAF . . . 993
Chapter32.Programmingfor theResource RecoveryServicesattachment facility . . 995
RRSAFcapabilitiesandrequirements . . . 995
RRSAFcapabilities . . . 995
RRSAFrequirements . . . 996
HowtouseRRSAF . . . 998
Summaryofconnectionfunctions . . . 998
Implicitconnections . . . 999
AccessingtheRRSAFlanguageinterface . . . 1000
GeneralpropertiesofRRSAFconnections . . . 1002
SummaryofRRSAFbehavior . . . 1004
RRSAFfunctiondescriptions . . . 1005
Registerconventions . . . 1005
Parameterconventionsforfunctioncalls . . . 1006
IDENTIFY:Syntaxandusage. . . 1006
SWITCHTO:Syntaxandusage . . . 1009
SIGNON:Syntaxandusage . . . 1012
AUTHSIGNON:Syntaxandusage. . . 1016
CONTEXTSIGNON:Syntaxandusage . . . 1020
SET_ID:Syntaxandusage. . . 1025
SET_CLIENT_ID:Syntaxandusage . . . 1026
CREATETHREAD:Syntaxandusage. . . 1029
TERMINATETHREAD:Syntaxandusage . . . 1031
TERMINATEIDENTIFY:Syntaxandusage . . . 1032
TRANSLATE:Syntaxandusage. . . 1034
FIND_DB2_SYSTEMS:Syntaxandusage . . . 1035
RRSAFconnectionexamples . . . 1036
Exampleofasingletask . . . 1036
Exampleofmultipletasks. . . 1037
ExampleofcallingSIGNONtoreuseaDB2thread . . . 1037
ExampleofswitchingDB2threadsbetweentasks . . . 1037
RRSAFreturncodesandreasoncodes. . . 1038
ProgramexamplesforRRSAF . . . 1039
SampleJCLforusingRRSAF. . . 1039
LoadinganddeletingtheRRSAFlanguageinterface . . . 1039
UsingdummyentrypointDSNHLIforRRSAF. . . 1039
ConnectingtoDB2forRRSAF . . . 1040
Chapter33.CICS-specific programmingtechniques . . . . . . . . . . . . . . . 1043
ControllingtheCICSattachmentfacilityfromanapplication . . . 1043
Improvingthreadreuse . . . 1043
DetectingwhethertheCICSattachmentfacilityisoperational. . . 1043
Chapter34.WebSphere MQwithDB2 . . . . . . . . . . . . . . . . . . . . . 1045
IntroductiontoWebSphereMQmessagehandlingandtheAMI . . . 1045
WebSphereMQmessages . . . 1045
WebSphereMQservices . . . 1046
WebSphereMQpolicies . . . 1046
UsingWebSphereMQfunctionsandstoredprocedures . . . 1046
CommitenvironmentforWebSphereMQfunctionsandstoredprocedures . . . 1050
HowtouseWebSphereMQfunctions. . . 1051
AsynchronousmessaginginDB2forz/OS . . . 1057
MQListenerinDB2forz/OS. . . 1059
ConfiguringandrunningMQListenerinDB2forz/OS . . . 1059
ConfiguringMQListenertasks . . . 1063
CreatingasamplestoredproceduretousewithMQListener . . . 1064
MQListenerexamples . . . 1065
||
Chapter35.UsingDB2 asa webservices consumerand provider . . . . . . . . . 1069
DB2asawebservicesconsumer . . . 1069
TheSOAPHTTPVandSOAPHTTPCuser-definedfunctions . . . 1069
SQLSTATEsforDB2asawebservicesconsumer . . . 1070
DB2asawebservicesprovider . . . 1071
Chapter36.Programmingtechniques: Questionsand answers . . . . . . . . . . 1073
Providingauniquekeyforatable . . . 1073
Scrollingthroughpreviouslyretrieveddata . . . 1073
Usingascrollablecursor . . . 1073
UsingaROWIDoridentitycolumn . . . 1074
Scrollingthroughatableinanydirection. . . 1075
Updatingdataasitisretrievedfromthedatabase. . . 1076
Updatingpreviouslyretrieveddata. . . 1076
Updatingthousandsofrows . . . 1076
Retrievingthousandsofrows . . . 1077
UsingSELECT* . . . 1077
Optimizingretrievalforasmallsetofrows . . . 1077
Addingdatatotheendofatable . . . 1078
TranslatingrequestsfromendusersintoSQLstatements . . . 1078
Changingthetabledefinition. . . 1079
Storingdatathatdoesnothaveatabularformat . . . 1079
Findingaviolatedreferentialorcheckconstraint . . . 1079
Part 7. Appendixes
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1081
AppendixA. DB2 sampletables . . . . . . . . . . . . . . . . . . . . . . . . 1083
Activitytable(DSN8910.ACT) . . . 1083
Departmenttable(DSN8910.DEPT). . . 1084
Employeetable(DSN8910.EMP). . . 1086
Employeephotoandresumetable(DSN8910.EMP_PHOTO_RESUME). . . 1089
Projecttable(DSN8910.PROJ) . . . 1090
Projectactivitytable(DSN8910.PROJACT) . . . 1091
Employeetoprojectactivitytable(DSN8910.EMPPROJACT) . . . 1092
Unicodesampletable(DSN8910.DEMO_UNICODE) . . . 1093
Relationshipsamongthesampletables . . . 1094
Viewsonthesampletables . . . 1094
Storageofsampleapplicationtables . . . 1099
Storagegroupforsampleapplicationdata . . . 1100
Databases . . . 1100
Tablespaces . . . 1100
AppendixB. Sampleapplications . . . . . . . . . . . . . . . . . . . . . . . 1103
Typesofsampleapplications . . . 1103
Usingthesampleapplications . . . 1105
SampleapplicationsinTSO . . . 1106
SampleapplicationsinIMS . . . 1108
SampleapplicationsinCICS . . . 1108
AppendixC. Running theproductivity-aid sampleprograms. . . . . . . . . . . . 1111
RunningDSNTIAUL . . . 1112
RunningDSNTIAD . . . 1118
RunningDSNTEP2andDSNTEP4 . . . 1119
AppendixD. Programming examples. . . . . . . . . . . . . . . . . . . . . . 1125
SampleCOBOLdynamicSQLprogram . . . 1125
PointersandbasedvariablesinthesampleCOBOLprogram . . . 1125
StorageallocationforthesampleCOBOLprogram . . . 1126
ExampleofthesampleCOBOLprogram . . . 1126