Você está na página 1de 16

DB2 Tutorial :Introduction to Databases What is data? A representation of facts or instruction in a form suitable for communication. What is a database?

It is a repository for stored data. What is a database System? An integrated and shared repository for stored data or collection of stored operational data used by application systems of some particular enterprise. Nothing more than a computer-based record keeping system Advantages of DBMS over File Management Systems Data redundancy Multiple Views Shared data Data independence logical!"hysical# Data dictionary Search $ersatility %ost effecti$e Security and %ontrol &eco$ery 'restart ( )ackup %oncurrency Ty es of Databases ! or Models" *ierarchical Model Network Model &elational Model +b,ect-+riented Model #$%&A&'#$'A( M)D%( -op down structure resembling an upside-down tree. "arent child relationship .irst logical database Model A$ailable on most of the Mainframe computers /0amples1 IMS *%TW)&+ M)D%( Does not distinguish between parent and child.Any record type can be associated with any number of arbitrary record types /nhanced to o$ercome limitations of other models but in reality there is minimal difference due to fre2uent enhancement /0ample1 IDMS &%(AT$)*A( M)D%( Data stored in the form of table consists of multiple rows and columns. /0amples1 D)3'+&A%4/'S5)AS/ )B,%'T-)&$%*T%D M)D%( Data attributes and methods that operate on those attributes are encapsulated instructions called ob,ects. Types of Integrity

/ntity Integrity &eferential Integrity Domain Integrity %ntity $ntegrity Is a state where no column that is part of a primary key can ha$e a null $alues. &eferential $ntegrity Is a state where e$ery foreign key in the first table must either match a primary key $alue in the second table or must be wholly null. Domain $ntegrity Integrating of information allowed in column. Entity Relationship Model /-& model is a logical representation of data for a business area. &epresented as entities relationship between entities and attributes of both relationships and entities. /-& models are outputs of analysis phase. /0ample of relational Structure %6S-+M/& places +&D/&S +&D/& has "&+D6%-S /ach order relates to only one customer one-to-one# Many orders can contain many products many-to-many# A customer can place any number of orders one-to-many# In last e0ample customer'order ( product are called entities An entities may transform into tables. -he uni2ue identity for information stored in an entity is called a primary key Attributes which define the characteristics of the table. DB2 )B,%'TS Stogroup Storage group# Database -able Space -able View Inde0 Stogrou ! Storage -rou " It is a collection of direct access $olume' all of the same de$ice type -he option is defined as a part of table space definitions 7hen a gi$en space needs to be e0tended' storage is ac2uired from the appropriate stogroup. Database A collection of logically related ob,ects 8 like table spaces' inde0 spaces'tables etc. Not a physical kind of ob,ect' may occupy more than one disk space. A S-+9&+6" ( )6../& "++4 must be defined for each database. In a gi$en database' all the spaces need not ha$e the same S-+9&+6". TAB(% S.A'%S 4ogical address space on secondary storage to hold one or more tables.

It is the storage unit for reco$ery and reorgani:ing purpose -hree types of table spaces are 1 o Simple o "artitioned o Segmented Sim le Table S a/es %an contain more than one stored tables Depending on application' storing more than one tables might enable faster retrie$al for ,oins using these tables. 6sually only one table is preferred. -his is because a single page can contain rows from all tables defined in the database. Segmented table s a/es %an contain more than one stored tables ' but in a segmented space. A ;segment< consists of a logically contiguous set of ;n< pages. No segment is allowed to contain records for more than one table. Se2uential access to a particular table is more efficient. 4ock -able on table locks only the table' not the entire table space. If a table is dropped 'the space for that table can be reclaimed within minimum reorgani:ation. .artitioned Table S a/e "rimarily used for $ery large tables +nly one table in a partitioned table space Indi$idual partitions can be independently reco$ered and reorgani:ed. Different partitions can be stored on different storage groups for efficient access. TAB(%S A table is a collection of rows and columns. -he data is stored on magnetic disks in a series of -A)4/S. /ach %+46MN contains some specific information about suppliers and each &+7 contains all the information about a particular supplier. .or e0ample S6""4I/& table looks like 1 S= SNAM/ S-A-6S %I-5 >>? "&ASAD 3> %*/NNAI >>3 VAS6 @> D/4*I >>@ SIVA ?> )+M)A5 0$%WS Views can be $ery practical ways of simplifying 2ueries by reducing the number of different tables. Views can also hide sensiti$e data from users who don<t need access to it. %&/A-/ VI/7 /M"AVI/7 AS S/4/%- /M"N+'NAM/'D/"-'B+) .&+M /M"

S1*)*1MS

Synonym is like a nick name to a table name and when no longer needed it can be dropped. Synonym access is specific to the user who has created it. STRUCTURED QUER !"#$U"$E%SQ!& A powerful database management language that performs the function of data manipulation' data definition and data control. A non-procedural language. -he capability to act on a set of data and the lack of need to know how to retrie$e it. It allows to specify 7*A- the result should be' N+- *+7 the result obtained. S2( T1.%S!Based on fun/tionality" DD4 - %&/A-/'A4-/& and D&+" DM4 - S/4/%-'INS/&-'6"DA-/ ( D/4/-/ D%4 - 9&AN- and &/V+C/ S2( T1.%S!)thers" Static or Dynamic SD4 /mbedded or Stand-alone SD4 #)W D) 1)3 3T$($4% S2(? It is usually accessed on-line. It can be used interacti$ely' such as S"6.I'DM. or it can be embedded in %+)+4'"4!I'ASS/M)4/& or .+&-&AN program. W#AT M$-#T 1)3 D) W$T# S2(? As an end-user you will be using SD4 on-line to access data and produce formatted reports. As an application programmer' you will use SD4 to e0tract data from one or more tables and pass these data to another program for additional processing. SD4 task is center about four basic functions ( these functions correspond to the four basic SD4 command S/4/%-' 6"DA-/' INS/&-' D/4/-/# #)W T) '&%AT% A S$M.(% S2( 23%&1? Search the table of your choice Select specific columns to be displayed from a table Select specific rows to be displayed from a table Specify the order in which to display data

#o5 do you s e/ify 5hi/h tables you 5ant to sele/t from? 7hich tables contain dataE 7hich columns to display from the tableE 7hich rows to displayE In which order to display the columns and!or rows. Any S/4/%- statement must specify a table If the table belongs to another user' you may ha$e to prefi0 the table name with the other user<s ID. #o5 do you s e/ify 5hi/h ')(3M*S you 5ant to dis lay? 4isting the name of the columns on a S/4/%- statement' separated by commas. S/4/%- SNAM/' S-A-6S .&+M S6""4I/&S Why not use the 678 in all your 9ueries ?

6sing the ;F< to indicate all columns should be displayed is inefficient if you don<t need to see all the columns. 5ou can put the columns in the order you want them. It is better to specify ,ust those column you want. #o5 do you s e/ify 5hi/h ro5s you 5ant to dis lay? 6sing 7*/&/ keyword . -he format is 7*/&/ followed by a condition or list of conditions. S/4/%- SNAM/ .&+M S6""4I/& 7*/&/ S-A-6SG@> 'an you ut the data in )rder? 6sing +&D/& )5 keyword to your 2uery SD4 automatically orders data in ascending order if you ha$e any +&D/& )5 statement in your 2uery. If you want your data in descending order' use the D/S% keyword. SE!ECT STATUS 'R(M SUPPLIERS (RDER B STATUS DESC 'an you order by more than one /olumn? 5ou can order by as many columns as you want. Simple add the columns you want to sort to the +&D/& )5 clause' separated by comma. /0ample1 SE!ECT SNAME ,STATUS, CITY 'R(M SUPPLIERS (RDER B STATUS,SNAME 3se of 6A*D8 and 6)&8 to ma:e a 9uery more s e/ifi/; Sometimes a single search condition is not precise enough to select only the rows you need.So you need to use the logical operator AND and +&. 5ou can link as many search e0pression as you want using AND and +&. 6sing both operator together ' searched e0pression linked by AND are paired up first."arentheses can be used to force e0pression to be paired together. #o5 do you avoid du li/ate data in your out ut? )y adding the keyword DIS-IN%- immediately following S/4/%- ' you suppress any duplicates. SE!ECT DISTI#CT STATUS 'R(M SUPPLIERS What are the relational o erators? *ere is the full list of operators1 S5M)+4 %+NDI-I+N G e2ual to H greater than I less than HG greater than or e2ual to IG lesser than or e2ual to IH less than or greater than 4IC/ containing certain characters )/-7//N within a range of $alues IN one of a set of $alues /ach condition also has a negati$e $ersion.

I# 4ets you retrie$e data from each row whose columns has a $alue e2ual to one of the se$eral listed $alues. /0ample1 W#%&% S-A-6S $* 3>'?>'@># Any row with S-A-6S column $alue of 3>'?>' @> is selected. /ach character $alue must be in 2uotes. Values are separated by comma ( $alues list is enclosed in parenthesis. BET)EE# 4ets you retrie$e data from each row whose columns has a $alue with two limits. /0ample1 W#%&% S-A-6S B%TW%%* ?> AND @> Any row with S-A-6S column $alue of ?> thru @> is selected. It can be used for both numeric and character $alues. -he two $alues must be separated by AND' the lower $alue must be the first $alue. !I*E 4ets you retrie$e data from each row whose columns has a $alue similar to the $alue specified in the 7*/&/ %4A6S/. /0ample1 W#%&% SNAM/ ($+% ;)J%< Any row with name column beginning with ;)< followed by AN5 VA46/ of AN5 4/N9-*' and ending with ;%< is selected. A ;J< represents any $alue of any length'where as an underscore ;A< represents any single character 4IC/ can<t use for any numeric column. )hat is #U!!+ A N644 is a column $alue that does not e0ists. It is not a blank' not is it :ero 8 it is a ;non-$alue<. -he columns must predefined to the D)MS as a column that may contain N644 $alues. #)W D)%S S2( T&%AT *3(( 0A(3%S? 9enerally' N644 $alues are ignored. If you perform a calculation using a column with N644 $alues ' those rows containing N644Ks are ignored and a dash will output as the result. N644 means LVA46/ 6NCN+7NM' so it cannot meet any of the standard search conditions. %<am le of *3(( values -o select all rows with a N644 $alue in the %+MM column' you must use 7*/&/ %+MM IS N644 as your search condition -o select all rows that do N+- ha$e a N644 $alue' you must use 7*/&/ %+MM IS N+- N644 as your search condition Note1 7*/&/ %+MM G > N 7ho has earned no commissionE 7*/&/ %+MM IS N644 7ho is ineligible for commissionE "RIT,METRIC E-.RESSI(#S An arithmetic e0pression is a calculation using numeric $alues and one or more of the arithmetic operators 1addition O#' subtraction -#' multiplication F#' and di$ision !#. /0ample1 SE!ECT SALARY + COMM,NAME,DEPT

Arithmetic e0pressions can also be used in a 7*/&/ clause1 ),ERE SALARY + COMM >5000.00 &3(%S F)& ')D$*- A&$T#M%T$' %=.&%SS$)*S Spaces on either side of the arithmetic symbols are optional. SALARY/12 +& SALARY / 12 5ou can combine column names and constants in arithmetic e0pressions. 1998 - JOIN_YR, 1.0*SALARY #)W D)%S S2( %0A(3AT% A&$T#M%T$' %=.&%SS$)*S? SD4 works from left to right' e$aluating multiplication and di$ision before addition and subtraction F' ! ' O' -#. *owe$er any e0pressions in parentheses are e$aluated first. B3$(T $* F3*'T$)* S6M MAP MIN AV9 %+6N- F# %+6N- DIS-IN%- col name# S3M %alculate the total $alue for a gi$en column or arithmetic e0pression SE!ECT SUM SALARY! 'R(M EMP MA= and M$* Display either the highest or lowest $alue found in the rows selected by the 2uery. SE!ECT M"- SALARY!,MI# SALARY! 'R(M EMP A0 Display the a$erage of all non-N644 columns SE!ECT "/$ SALARY! 'R(M EMP AV9 disregards any rows with N644s in any column in$ol$ed in the a$eraging e0pression Integer columns are not rounded' so result may be inaccurate. -o con$ert an integer column to a decimal column multiply by ?.> as part of the AV9 e0pression. "/$ 1.0 * STATUS! ')3*T!7" It counts all the rows selected by a 2uery SE!ECT C(U#T%0& 'R(M SUPPLIERS ')3*T!D$ST$*'T /ol name" It counts only those rows that ha$e a uni2ue $alue in the specified column SE!ECT C(U#T%DISTI#CT STATUS& 'R(M SUPPLIERS %+6N- F# counts all the rows selected %+6N- DIS-IN%- col name# does not count rows with a duplicate $alue in the specified column. %+6N- DIS-IN%- colAname# does not count rows that ha$e N644S in the specified column. #)W D)%S S2( '&%AT%S S3MMA&1 DATA

7hen you re2uest a built-in summary functions' SD4 goes through se$eral steps to reach a result. .irst' all the rows and columns are selected. -his intermediate result is kept in a temporary table. Ne0t' the system process your 9&+6" )5 re2uest' creating a temporary table for each 9&+6" and putting the appropriate rows in each table. -hen the built-in functions are calculated. If' for e0ample you re2uested an AV9' then the a$erage for each temporary sub group is calculated. -&)3. B1 9&+6" )5 outputs a summary table 8 one line for each group. 9&+6" )5 can only be used in con,unction with built-in functions. 9&+6" )5 follows .&+M and 7*/&/ and precedes +&D/& )5 /0ample1 SE!ECT DEPT, M"- SALARY! 'R(M EMP $(U. B DEPT It will produce a table listing the ma0imum salary $alue for each department. #A0$* It is similar in function to the 7*/&/ clause Its purpose is to further define a ;group< specified in the 9&+6" )5 statement SE!ECT DEPT, "/$ SALARY! 'R(M EMP $R(U. B DEPT ,"/I#$ COUNT *!>" *AVIN9 can only be used in con,unction with 9&+6" )5 *AVIN9 must immediately follow the 9&+6" )5 clause *AVIN9 can only compare built-in functions not indi$idual columns 1(I#I#$ Boining tables in$ol$es matching the rows of one table with related rows of another table to produce a table consisting of rows with columns from both the original tables. BAS$' .&$*'$.(%S )F ,)$*$*- TAB(%S It will combine related information from two tables into a single row. If a $alue appears once in the L,oining columnM of one table' but se$eral times in the other' the higher number of occurrences will appear in the output table. If a $alue e0ists in the L,oining columnM of one table' but not in the other' no row appears in the output table with that $alue. 1(I#I#$ C(!UM# It is a column that is common to all the tables being ,oined and contains the row $alues that tie one table to ne0t. #)W D) 1)3 A'T3A((1 T$% T#% TAB(%S T)-%T#%&? 7ith a special type of 7*/&/ clause called the ,oining condition W#%&% /M".D/"-N+ G D/"-.D/"-N+ /0ample1 SE!ECT ITEM,PRICE,COLOR 'R(M T#$%&1,T#$%&2 ),ERE T#$%&1.ITEM ' T#$%&2.ITEM MER$I#$ Merging tables also in$ol$es combining data from two tables' but the rows are not ,oined together. /0ample1SE!ECT *'R(M EMP U#I(# SE!ECT * 'R(M SUPPLIER M%&-$*- 23%&1 ')D$*

Select data from one table Specify 6NI+N or 6NI+N A44 to indicate M/&9/ Select data from second table /0ample1 SE!ECT * 'R(M T#$%&_1 U#I(# SE!ECT * 'R(M T#$%&_2 -he 6NI+N or 6NI+N A44 keyword must be entered after the first S/4/%statement 3*$)* vs; 3*$)* A(( 6NI+N sorts the result tables' 6NI+N A44 does not. In other words' 6NI+N mi0es rows together in the output. 6NI+N A44 outputs all the rows from the first table that meet the search condition. 6NI+N remo$es duplicate rows' 6NI+N A44 does not. W#%* T) M%&-% TW) TAB(%S /ach column selected from first table must be compatible with the corresponding columns from the second table. A numeric column are compatible with numeric column' a character column to a character column' and so on. Numeric data types need not be the same column length 5ou must select the same number of columns from each tables. '&%AT$*- A*D 3.DAT$*- TAB(%S -o create a new table you must use the SD4 statement %&/A-/ -A)4/. 5ou must specify the table name and the names and attributes of each column. RU!ES '(R T"B!E #"ME Ma0imum ?Q characters "ermissible characters o letters of the alphabet o R' =' and S o numbers o underscore A# -he first character must be alphabetic or R'=' or S D"T" T .ES Data type depends on the nature of the data itself and will always be one of two types 8 N6M/&I% or %*A&A%-/& o -ypes of %*A&A%-/& column %*A& 8 Allows any $alues to be entered in the column. All entries are the same length VA&%*A& 8 Allows any $alues to be entered in the column. All entries are the $arying length o -ypes of N6M/&I% columns IN-/9/& - .or $ery large integers up to 3'?TU'TQ@'VTU SMA44IN- - .or small integer up to WWWWW -able Space D/%IMA4 - .or numbers with a fi0ed number of decimal places after the decimal point. -he number can ha$e a total of ?X digits .4+A- -.or $ery large numbers with an undetermined number of decimal places after the decimal point -ypes of DA-/!-IM/ columns o DA-/ - Dates are stored in 5555MMDD format

-IM/ - -imes are stored on a 3T-hour clock in **MMSS format -IM/S-AM" 8 -IM/S-AM" columns contain both date and time information' with the time $alue accurate to the millisecond. $R"#T 2 RE/(*E "ri$ileges in D)3 to control accessing data -o grant access to a table or $iew you must run a 2uery that specifies three things in the following order o -he pri$ileges you are granting S/4/%-'INS/&-'D/4/-/'6"DA-/ or A44# o -he name of the table or $iew o -he user or users to whom you are granting access S-+9&+6" Storage group# -o grant e$erything' use 9&AN- A44 -o grant a pri$ilege to /V/&5)+D5 ' you grant -+ "6)4I% .&$0$(%-%S (RANT ALL ON TA)LE EMP TO PU)LIC RE*O+E ALL ON EMP TO PU)LIC 'A* 1)3 '#A*-% A TAB(% )& 0$%W AFT%& 1)3 '&%AT% $T? -he only change you can make to a table or $iew after it has been created is to add an additional column. -his is done with the SD4 command A4-/& o ALTER TA)LE EMP ADD COMM DECIMAL , ,2! D&). 7hen you no longer need a -A)4/' VI/7' or S5N+N5M you can D&+" them. o D&+" -A)4/ S6""4I/& o D&+" VI/7 /M"AVI/7 o D&+" S5N+N5M S $*S%&T$*- A TAB(% -here must be one $alue for each column Separate $alues with commas "ut character $alues in single 2uotes Numeric $alues do not re2uire 2uotes If you want enter the $alues in a different order' there is an alternati$e way of inserting a row' by listing the columns along with their assigned $alues o I#SERT I#T( SUPPLIER S-,STATUS,SNAME! /"!UES .S1/,"0,/*AST/! 3.DAT% SD4 pro$ides two commands for updating row $alues 8 6"DA-/ and S/-. 6"DA-/ tells SD4 which table you want to update and S/- pro$ides the name of the column to update and the new $alue for the column. 5ou tell SD4 which row to update with a 7*/&/ clause can be $ery specific' so that a single row gets changed' or it can be $ery general' so that many rows get updated. o I)>UPDATE SUPPLIER SET STATUS ' 00 ),ERE S- ' .S1/ o U.D"TE EMP SET SALARY ' SALARY + SALARY *.01
o

D%(%T% 6sing the D/4/-/ command you can delete rows and using 7*/&/ clause you can specify which rows you want to delete. o DE!ETE 'R(M SUPPLIER ),ERE S- ' .S1/ 'om le< S2(8s +ne terms a SD4 to be comple0 when data that is to be retrie$ed comes from more than one table. SD4 pro$ides two ways of coding a comple0 SD4 o Sub2ueries and Boin S3B 23%&$%S Nested select statements. Specified using the IN or N+- IN predicate' e2uality or non-e2uality predicate and comparati$e operator. 7hen using the e2uality' non-e2uality or comparati$e operators the inner 2uery should return only a single $alue. Nested loop statements gi$es the user fle0ibility for 2uerying multiple tables. A speciali:ed form is a correlated sub 2uery. It works on top-bottom-top fashion. Non correlated sub 2uery works in bottom to top fashion. ,)$*S +6-/& B+IN INN/& B+IN )3T%& ,)$* .or one or more tables being ,oined both matching and the non-matching rows are returned. Duplicate columns may be eliminated. Non-matching columns will ha$e nulls. $**%& ,)$* *ere there is a possibility one or more of the rows from either or both tables being ,oined will not be included in the table that results from the ,oin operation QM'3 Query Manage4ent 'acility It is an MVS and VM-based 2uery tools Allows end users to enter SD4 2ueries to produce a $erity of reports and graphs as a result of this 2uery. DM. 2ueries can be formulated in se$eral ways1 by direct SD4 statements' by means of relational prompted 2uery interface S.3F$ !S2( .ro/essing 3sing File $n ut" Supports the on-line e0ecution of SD4 statements from a -S+ terminal. 6sed for de$elopers to check SD4 statements or $iew table details. S"6.I menu contains the input file in which the SD4 statements are coded ' option for default settings and editing and output file. .rogra4 .reparation "recompile %ompile ( 4ink )ind o "ackage o "lan

.re/om ile Searches all the SD4 statements and D)3 related IN%46D/ members and comments out e$ery SD4 statement in the program. -he SD4 statements are replaced by a %A44 to the D)3 runtime interface module along with parameter. All SD4 statements are e0tracted and put in a D)&M. "laces a time stamp in the modified source and the D)&M so that these are tied. All D)3 related IN%46D/ statements must be placed between /P/% SD4 ( /ND-/P/% key words for the precompiler to recogni:e them. 'om ile > (in: Modified precompiler %+)+4 output is complied. %omplied source is link edited to an e0ecutable load module. Bind A type of compiler for SD4 statement. It reads the SD4 statements from the D)&M and produces a mechanism to access data as directed by the SD4 statements being bound. %hecks synta0' check for correctness of table ( column definitions against the catalog information ( performs authori:ation $alidation. .a/:age It is a single bound D)&M with optimi:ed access paths. It also contains a location identifier a collection identifier and a package identifier. A package can ha$e multiple $ersions ' each with it<s own $ersion identifier. Advantages of .a/:age &educed bind time. Versioning. "ro$ides remote data access. %an specify bind options at the programmer le$el. .lan An application plan contains one or both of the following elements o A list of package names. o -he bound form of SD4 statements taken from one or more D)&M. /$ery D)3 application re2uires an application plan. "lans are created using the D)3 sub commands )IND "4AN. DB2 (pti4i5er Analy:es the SD4 statements and determines the most efficient way to access data' gi$es physical data independence. It e$aluates the following factors1 %"6 cost' I!+ cost' D)3 catalogue statistics ( the SD4 statements It estimate %"6 time ' cost in$ol$ed in applying predicates tra$ersing pages ( sorting. It estimates the cost of physically retrie$ing and writing data. Ste s involved in /reating a DB2 A li/ation 6sing /mbedded SD4 6sing *ost Variables D%49/N# 6sing SD4%A

"recompile %ompile ( 4inkedit the program )ind %mbedding S2( Statements It is like the file I!+ Normally the embedded SD4 statements contain the host $ariables coded with the IN-+ clause of the S/4/%- statement. -hey are delimited with E-EC SQ! 1 E#D3E-EC /0ample1 /P/% SD4 S/4/%- eno'ename IN-+ 1h-eno'1h-ename .&+M employee 7*/&/ enoG?>>? /ND-/P/%. #ost 0ariables -hese are $ariables defined in the host language to use the predicates of a D)3 table. -hese are referenced in the SD4 statement. A means of mo$ing data from and to D)3 tables. D%49/N produces host $ariables the same as the columns of the tables. D'(-%* Issued for a single table. "repares the structures of the table in a %+)+4 copy book. -he copy book contains a SD4 D/%4A&/ -A)4/ statement along with a working storage host $ariable definition for the table. S2('A An SD4%A is a structure or collection of $ariables that is updated after each SD4 statement e0ecutes. An application program that contains e0ecutable SD4 statements must pro$ide e0actly one SD4%A. '3&S)& 6sed when more than one row are to be selected. %an be used for modifying data using ;F)& 3.DAT% )F< clause. The 'our Cursor control State4ents D/%4A&/ 1 name assigned for a particular SD4 statement. +"/N1 )uilds the result table . ./-%* 1 &eturns data from the results table one row at a time and assign the $alue to the specified host $ariables. %4+S/1 &eleases all resources used by the cursor. D%'(A&%: /P/% SD4 D/%4A&/ empcur %6&S+& .+& S/4/%- empno' ename' dept' ,ob .&+M emp 7*/&/ deptG;D??< .+& 6"DA-/ +. ,ob /ND-/P/%.

).%*: for the +"/N statement /P/% SD4

+"/N empcur /ND-/P/%. F%T'#: for the ./-%* statement /P/% SD4 ./-%* empcur IN-+ 1empno' 1ename' 1dept' 1,ob

/ND-/P/%.

W#%*%0%&: for the 7*/N/V/& clause /P/% SD4 7*/N/V/& N+- .+6ND 9+ -+ close-empcur /ND-/P/%. 3.DAT%: for the update statement using cursors /P/% SD4 6"DA-/ emp S/- ,obG1new-,ob 7*/&/ %6&&/N- +. empcur /ND-/P/%. D%(%T%: for the delete statement using cursor. /P/% SD4 D/4/-/ .&+M /M" 7*/&/ %6&&/N- +. empcur /ND-/P/%. DB2 !(C*I#$ 4ocking is used to pro$ide multiple user access to the same system. D)3 uses locking ser$ices pro$ided by an MVS subsystem called IMS &esource 4ocking Manager I&4M#. %< li/it (o/:ing Fa/ilities -he SD4 statement 4+%C -A)4/ -he IS+4A-I+N parameter on the )IND "A%CA9/ command 8 the two possible $alues are && &epeatable &ead# ( %S %ursor Stability#. %S is the $alue specified if the application program is used in an on-line en$ironment. -he 4+%CSIY/ parameter 8 physically D)3 locks data in terms of pages or tables or table spaces. -his parameter is specified in %&/A-/ or A4-/& table space option ;4+%CSIY/<. -he options are -ablespace' -able' "age or Any. -he A%D6I&/ ! &/4/AS/ parameters on the )IND "4AN command specifies when table locks to be ac2uired and release. o A%D6I&/ 6S/ ! A44+%A-/ o &/4/S/ %+MMI- ! D/A44+%A-/ Catalogue Tables &epository for all D)3 ob,ects 8 contains T@ tables

/ach table maintains data about an aspects of the D)3 en$ironment -he data refers to information about table space' tables' inde0es etcN S5SI)M.S5S-A)4/S' S5SI)M.S5SIND/PS' S5SI)M.S5S%+46MNS etcN

DB2 3tilities:UTI!ITIES %*/%C %+"5 M/&9/%+"5 &/%+V/& 4+AD &/+&9 &6NS-A-S /P"4AIN '#%'+ %hecks the integrity of D)3 data structures %hecks the referential integrity between two tables and also checks D)3 inde0es for consistency. %an delete in$alid rows and copies them to a e0ception table. ').1 6sed to create an image copy for the complete table space or a portion of the table space- full image copy or incremental image copy. /$ery successful e0ception of %+"5 utility places in the table' S5SI)M.S5S%+"5' at least one row that indicates the status of the image copy. M%&-%').1 -he M/&9/%+"5 utility combines multiple incremented image copy data sets into a new full or incremental image copy dataset. &%')0%& &estore Db3 table spaces and inde0es to a specific instance. Data can be reco$ered for a single page' pages that contain I!+ errors' a single partition or an entire tablespace. Standard unit of reco$ery is table space. ()AD -o accomplish bulk inserts into D)3 table %an replace the current data append to it If a ,ob terminates in any phase of 4+AD &/"4A%/' the utility has to be terminated and rerun &%)& -o reorgani:e D)3 tables and inde0es and there by impro$ing their efficiency of access re-clusters data' resets free space to the amount specified in the ;create DD4< 'statement and deletes and redefines underlying VSAM datasets for stogroup defined ob,ects.

%=.(A$* /0plain can be used to obtain the details about the access paths chosen by the D)3 optimi:er for SD4 statements. 6sed specifically for performance monitoring. 7hen /P"4AIN is re2uested the access paths that the D)3 chooses are put in coded format into the table "4ANA-A)4/' which is created in the default database by the user. -he other method is specifying /P"4AIN 5/S with )IND command -he "4ANA-A)4/ is to be 2ueried to get the re2uired information Since the /P"4AIN results are dependent on the D)3 catalogue' it is better to run &6NS-A- before running /P"4AIN.

Você também pode gostar