Вы находитесь на странице: 1из 12

DB2 - Interview Questions with Answers 1) How would you find out the total number of rows in a table?

se !"#"$% $& '%()) *** 2) How do you eliminate du+li,ate values in !"#"$%? se !"#"$% DI!%I'$% *** -) How do you sele,t a row usin. inde/es? !+e,ify the inde/ed ,olumns in the 0H"1" ,lause* 2) 0hat are a..re.ate fun,tions? Bulit-in mathemati,al fun,tions for use in !"#"$% ,lause* 3) How do you find the ma/imum value in a ,olumn? se !"#"$% 4A5(*** 6) $an you use 4A5 on a $HA1 ,olumn? 7"!* 8) 4y !Q# statement !"#"$% A9:(!A#A17) ;1&4 "4< yields ina,,urate results* 0hy? Be,ause !A#A17 is not de,lared to have ' ##s and the em+loyees for whom the salary is not =nown are also ,ounted* >) How do you retrieve the first 3 ,hara,ters of ;I1!%'A4" ,olumn of "4< table? !"#"$% ! B!%1(;I1!%'A4"?1?3) ;1&4 "4<@ A) How do you ,on,atenate the ;I1!%'A4" and #A!%'A4" from "4< table to .ive a ,om+lete name? !"#"$% ;I1!%'A4" BB C C BB #A!%'A4" ;1&4 "4<@ 1D) 0hat is the use of 9A# " fun,tion? 1* Avoid -ve !Q#$&D"s by handlin. nulls and Eeroes in ,om+utations 2* !ubstitute a numeri, value for any nulls used in ,om+utation 11) 0hat is 'I&'? 'I&' A##? 'I&' F eliminates du+li,ates 'I&' A##F retains du+li,ates Both these are used to ,ombine the results of different !"#"$% statements* !u++ose I have five !Q# !"#"$% statements ,onne,ted by 'I&'G 'I&' A##? how many times should I s+e,ify 'I&' to eliminate the du+li,ate rows? &n,e*

12) 0hat is the restri,tion on usin. It has to be in a $ 1!&1*

'I&' in embedded !Q#?

1-) In the 0H"1" ,lause what is B"%0""' and I'? B"%0""' su++lies a ran.e of values while I' su++lies a list of values* 12) Is B"%0""' in,lusive of the ran.e values s+e,ified? 7es* 13) 0hat is H#II"H used for in 0H"1" ,lause? 0hat are the wild,ard ,hara,ters? #II" is used for +artial strin. mat,hes* CJK ( for a strin. of any ,hara,ter ) and CLK (for any sin.le ,hara,ter ) are the two wild ,ard ,hara,ters* 16) 0hen do you use a #II" statement? %o do +artial sear,h e*.* to sear,h em+loyee by name? you need not s+e,ify the ,om+lete name@ usin. #II"? you ,an sear,h for +artial strin. mat,hes* 18) 0hat is the meanin. of unders,ore ( CLK ) in the #II" statement? 4at,h for any sin.le ,hara,ter* 1>) 0hat do you a,,om+lish by :1& < B7 *** HA9I': ,lause? :1& < B7 +artitions the sele,ted rows on the distin,t values of the ,olumn on whi,h you .rou+ by* HA9I': sele,ts :1& <s whi,h mat,h the ,riteria s+e,ified 1A) $onsider the em+loyee table with ,olumn <1&M"$% nullable* How ,an you .et a list of em+loyees who are not assi.ned to any +roNe,t? !"#"$% "4<'& ;1&4 "4< 0H"1" <1&M"$% I! ' ##@ 2D) 0hat is the result of this Ouery if no rows are sele,tedF !"#"$% ! 4(!A#A17) ;1&4 "4< 0H"1" Q A#PC4!$K@ ' ## 21) 0hy !"#"$% ) is not +referred in embedded !Q# +ro.rams? ;or three reasonsF If the table stru,ture is ,han.ed ( a field is added )? the +ro.ram will have to be modified <ro.ram mi.ht retrieve the ,olumns whi,h it mi.ht not use? leadin. on IG& over head* %he ,han,e of an inde/ only s,an is lost*

0hat are ,orrelated subOueries? A subOuery in whi,h the inner ( nested ) Ouery refers ba,= to the table in the outer Ouery* $orrelated subOueries must be evaluated for ea,h Oualified row of the outer Ouery that is referred to*

22) 0hat are the issues related with ,orrelated subOueries? ??? 2-) 0hat is a ,ursor? why should it be used? $ursor is a +ro.rammin. devi,e that allows the !"#"$% to find a set of rows but return them one at a time* $ursor should be used be,ause the host lan.ua.e ,an deal with only one row at a time* 22) How would you retrieve rows from a DB2 table in embedded !Q#? "ither by usin. the sin.le row !"#"$% statements? or by usin. the $ 1!&1* A+art from ,ursor? what other ways are available to you to retrieve a row from a table in embedded !Q#? !in.le row !"#"$%s* 23) 0here would you s+e,ify the D"$#A1" $ 1!&1 statement? !ee answer to ne/t Ouestion* 26) How do you s+e,ify and use a ,ursor in a $&B&# +ro.ram? se D"$#A1" $ 1!&1 statement either in wor=in. stora.e or in +ro,edure division(before o+en ,ursor)? to s+e,ify the !"#"$% statement* %hen use &<"'? ;"%$H rows in a loo+ and finally $#&!"* 28) 0hat ha++ens when you say &<"' $ 1!&1? If there is an &1D"1 B7 ,lause? rows are fet,hed? sorted and made available for the ;"%$H statement* &ther wise sim+ly the ,ursor is +la,ed on the first row* 2>) Is D"$#A1" $ 1!&1 e/e,utable? 'o* 2A) $an you have more than one ,ursor o+en at any one time in a +ro.ram ? 7es* -D) 0hen you $&44I%? is the ,ursor ,losed? 7es* -1) How do you leave the ,ursor o+en after issuin. a $&44I%? ( for DB2 2*- or above only )

se 0I%H H&#D o+tion in D"$#A1" $ 1!&1 statement* But? it has not effe,t in +suedo-,onversational $I$! +ro.rams* -2) :ive the $&B&# definition of a 9A1$HA1 field* A 9A1$HA1 ,olumn 1"4A1I! would be defined as followsF *** 1D 1"4A1I!* 2A 1"4A1I!-#"' <I$ !A(2) !A:" $&4<* 2A 1"4A1I!-%"5% <I$ 5(1A2D)* --) 0hat is the +hysi,al stora.e len.th of ea,h of the followin. DB2 data ty+esF DA%"? %I4"? %I4"!%A4<? DA%"F 2bytes %I4"F -bytes %I4"!%A4<F 1Dbytes -2) 0hat is the $&B&# +i,ture ,lause of the followin. DB2 data ty+esF DA%"? %I4"? %I4"!%A4<? DA%"F <I$ 5(1D) %I4" F <I$ 5(D>) %I4"!%A4<F <I$ 5(26) -3) 0hat is the $&B&# +i,ture ,lause for a DB2 ,olumn defined as D"$I4A#(11?2)? <I$ !A(A)9AA $&4<--* 'oteF In D"$I4A#(11?2)? 11 indi,ates the siEe of the data ty+e and 2 indi,ates the +re,ision* -6) 0hat is D$#:"' ? De$#arations :"'eratorF used to ,reate the host lan.ua.e ,o+y boo=s for the table definitions* Also ,reates the D"$#A1" table* -8) 0hat are the ,ontents of a D$#:"'? 1* "5"$ !Q# D"$#A1" %AB#" statement whi,h .ives the layout of the tableGview in terms of DB2 dataty+es* 2* A host lan.ua.e ,o+y boo= that .ives the host variable definitions for the ,olumn names* ->) Is it mandatory to use D$#:"'? If not? why would you use it at all? It is not mandatory to use D$#:"'* sin. D$#:"'? hel+s dete,t wron.ly s+elt ,olumn names et,* durin. the +re,om+ile sta.e itself ( be,ause of the D"$#A1" %AB#" )* D$#:"' bein. a tool? would .enerate a,,urate host variable definitions for the table redu,in. ,han,es of error* -A) Is D"$#A1" %AB#" in D$#:"' ne,essary? 0hy it used?

It not ne,essary to have D"$#A1" %AB#" statement in D$#:"'* %his is used by the +re-,om+iler to validate the table-name? view-name? ,olumn name et,*? durin. +re-,om+ile* 2D) 0ill +re,om+ile of an DB2-$&B&# +ro.ram bomb? if DB2 is down? 'o* Be,ause the +re,om+iler does not refer to the DB2 ,atalo.ue tables* 21) How is a ty+i,al DB2 bat,h +.m e/e,uted ? 1* se D!' utility to run a DB2 bat,h +ro.ram from native %!&* An e/am+le is shownF D!' !7!%"4(D!<-) 1 ' <1&:1A4("DD28DBD) <#A'("DD28DBD) #IB(H"D D1%*&BM*#&AD#IBH) "'D 2* se IIM";%D1 utility +ro.ram to run the above D!' ,ommand in a M$#* Assumin. that a siteKs standard is that +.m name P +lan name? what is the easiest way to find out whi,h +.ms are affe,ted by ,han.e in a tableKs stru,ture ? Query the ,atalo.ue tables !7!<#A'D"< and !7!<A$ID"<* 22) 'ame some fields from !Q#$A* !Q#$&D"? !Q#"114? !Q#"11D 2-) How ,an you Oui,=ly find out the Q of rows u+dated after an u+date statement? $he,= the value stored in !Q#"11D(-)* 22) 0hat is "5<#AI'? "5<#AI' is used to dis+lay the a,,ess +ath as determined by the o+timiEer for a !Q# statement* It ,an be used in !< ;I (for sin.le !Q# statement ) or in BI'D ste+ (for embedded !Q# )* 23) 0hat do you need to do before you do "5<#AI'? 4a=e sure that the <#A'L%AB#" is ,reated under the A %HID* 26) 0here is the out+ut of "5<#AI' stored? In userid*<#A'L%AB#" 28) "5<#AI' has out+ut with 4A%$H$&#! P D* 0hat does it mean? a nonmat,hin. inde/ s,an if A$$"!!%7<" P I* 2>) How do you do the "5<#AI' of a dynami, !Q# statement? 1* se !< ;I or Q4; to "5<#AI' the dynami, !Q# statement 2* In,lude "5<#AI' ,ommand in the embedded dynami, !Q# statements 2A) How do you simulate the "5<#AI' of an embedded !Q# statement in !< ;IGQ4;? :ive an e/am+le with a host variable in 0H"1" ,lause*)

se a Ouestion mar= in +la,e of a host variable ( or an un=nown value )* e*.* !"#"$% "4<L'A4" ;1&4 "4< 0H"1" "4<L!A#A17 R ? 3D) 0hat are the isolation levels +ossible ? $!F $ursor !tability 11F 1e+eatable 1ead 31) 0hat is the differen,e between $! and 11 isolation levels? $!F 1eleases the lo,= on a +a.e after use 11F 1etains all lo,=s a,Ouired till end of transa,tion 32) 0here do you s+e,ify them ? I!&#A%I&' #"9"# is a +arameter for the bind +ro,ess* 3-) 0hen do you s+e,ify the isolation level? How? Durin. the BI'D +ro,ess* I!&#A%I&' ( $!G11 )*** I use $! and u+date a +a.e* 0ill the lo,= be released after I am done with that +a.e? 'o* 32) 0hat are the various lo,=in. levels available? <A:"? %AB#"? %AB#"!<A$" 33) How does DB2 determine what lo,=-siEe to use? 1* Based on the lo,=-siEe .iven while ,reatin. the tables+a,e 2* <ro.rammer ,an dire,t the DB2 what lo,=-siEe to use -* If lo,=-siEe A'7 is s+e,ified? DB2 usually ,hooses a lo,=-siEe of <A:" 36) 0hat are the disadvanta.es of <A:" level lo,=? Hi.h resour,e utiliEation if lar.e u+dates are to be done 38) 0hat is lo,= es,alation? <romotin. a <A:" lo,=-siEe to table or tables+a,e lo,=-siEe when a transa,tion has a,Ouired more lo,=s than s+e,ified in ' 4#I%!* #o,=s should be ta=en on obNe,ts in sin.le tables+a,e for es,alation to o,,ur* 3>) 0hat are the various lo,=s available? !HA1"? "5$# !I9"? <DA%" 3A) $an I use #&$I %AB#" on a view? 'o* %o lo,= a view? ta=e lo,= on the underlyin. tables* 6D) 0hat is A#%"1 ? !Q# ,ommand used to ,han.e the definition of DB2 obNe,ts*

61) 0hat is a DB14? <#A' ? DB14F DataBase 1eOuest 4odule? has the !Q# statements e/tra,ted from the host lan.ua.e +ro.ram by the +re-,om+iler* <#A'F A result of the BI'D +ro,ess* It has the e/e,utable ,ode for the !Q# statements in the DB14* 62) 0hat is A$Q I1"G1"#"A!" in BI'D? Determine the +oint at whi,h DB2 a,Ouires or releases lo,=s a.ainst table and tables+a,es? in,ludin. intent lo,=s* 6-) 0hat else is there in the <#A' a+art from the a,,ess +ath? <#A' has the e/e,utable ,ode for the !Q# statements in the host +ro.ram 62) 0hat ha++ens to the <#A' if inde/ used by it is dro++ed? <lan is mar=ed as invalid* %he ne/t time the +lan is a,,essed? it is rebound* 63) 0hat are <A$IA:"! ? %hey ,ontain e/e,utable ,ode for !Q# statements for one DB14* 66) 0hat are the advanta.es of usin. a <A$IA:"? 1* Avoid havin. to bind a lar.e number of DB14 members into a +lan 2* Avoid ,ost of a lar.e bind -* Avoid the entire transa,tion bein. unavailable durin. bind and automati, rebind of a +lan 2* 4inimiEe fallba,= ,om+le/ities if ,han.es result in an error* 68) 0hat is a ,olle,tion? a user defined name that is the an,hor for +a,=a.es* It has not +hysi,al e/isten,e* 4ain usa.e is to .rou+ +a,=a.es* In !< ;I su++ose you want to sele,t ma/* of 1DDD rows ? but the sele,t returns only 2DD rows* 6>) 0hat are the 2 sOl,odes that are returned? 1DD ( for su,,essful ,om+letion of the Ouery )? D (for su,,essful $&44I% if A %&$&44I% is set to 7es)* 6A) How would you +rint the out+ut of an !Q# statement from !< ;I? <rint the out+ut dataset* 8D) How do you +ull u+ a Ouery whi,h was +reviously saved in Q4; ? ?? 81) #ot of u+dates have been done on a table due to whi,h inde/es have .one haywire* 0hat do you do? #oo=s li=e inde/ +a.e s+lit has o,,urred* D& a 1"&1: of the inde/es*

82) 0hat is dynami, !Q#? Dynami, !Q# is a !Q# statement ,reated at +ro.ram e/e,ution time* 8-) 0hen is the a,,ess +ath determined for dynami, !Q#? At run time? when the <1"<A1" statement is issued* 82) !u++ose I have a +ro.ram whi,h uses a dynami, !Q# and it has been +erformin. well till now* &ff late? I find that the +erforman,e has deteriorated* 0hat ha++ened? <robably 1 ' !%A%! is not done and the +ro.ram is usin. a wron. inde/ due to in,orre,t stats* <robably 1 '!%A%! is done and o+timiEer has ,hosen a wron. a,,ess +ath based on the latest statisti,s* 83) How does DB2 store ' ## +hysi,ally? as an e/tra-byte +refi/ to the ,olumn value* +hysi,ally? the nul +refi/ is He/ KDDK if the value is +resent and He/ C;;K if it is not* 86) How do you retrieve the data from a nullable ,olumn? se null indi,ators* !ynta/ *** I'%& FH&!%9A1F' ##I'D 88) 0hat is the +i,ture ,lause of the null indi,ator variable? !A(2) $&4<* 8>) 0hat does it mean if the null indi,ator has -1? D? -2? -1 F the field is null D F the field is not null -2 F the field value is trun,ated 8A) How do you insert a re,ord with a nullable ,olumn? %o insert a ' ##? move -1 to the null indi,ator %o insert a valid value? move D to the null indi,ator >D) 0hat is 1 '!%A%!? A DB2 utility used to ,olle,t statisti,s about the data values in tables whi,h ,an be used by the o+timiEer to de,ide the a,,ess +ath* It also ,olle,ts statisti,s used for s+a,e mana.ement* %hese statisti,s are stored in DB2 ,atalo. tables* >1) 0hen will you ,hose to run 1 '!%A%!? After a load? or after mass u+dates? inserts? deletes? or after 1"&1:* >2) :ive some e/am+le of statisti,s ,olle,ted durin. 1 '!%A%!? Q of rows in the table <er,ent of rows in ,lusterin. seOuen,e

Q of distin,t values of inde/ed ,olumn Q of rows moved to a nearbyGfarway +a.e due to row len.th in,rease >-) 0hat is 1"&1:? 0hen is it used? 1"&1: reor.aniEes data on +hysi,al stora.e to re,lutser rows? +ositionin. overflowed rows in their +ro+er seOuen,e? to re,laim s+a,e? to restore free s+a,e* It is used after heavy u+dates? inserts and delete a,tivity and after se.ments of a se.mented tables+a,e have be,ome fra.mented* >2) 0hat is I4A:"$&<7 ? It is full ba,=u+ of a DB2 table whi,h ,an be used in re,overy* >3) 0hen do you use the I4A:"$&<7? %o ta=e routine ba,=u+ of tables After a #&AD with #&: '& After 1"&1: with #&: '& >6) 0hat is $&<7 <"'DI': status? A state in whi,h? an ima.e ,o+y on a table needs to be ta=en? In this status? the table is available only for Oueries* 7ou ,annot u+date this table* %o remove the $&<7 <"'DI': status? you ta=e an ima.e ,o+y or use 1"<AI1 utility* >8) 0hat is $H"$I <"'DI': ? 0hen a table is #&ADed with "';&1$" '& o+tion? then the table is left in $H"$I <"'DI': status* It means that the #&AD utility did not +erform ,onstraint ,he,=in.* >>) 0hat is Q I"!$"? A Q I"!$" flushes all DB2 buffers on to the dis=* %his .ives a ,orre,t sna+shot of the database and should be used before and after any I4A:"$&<7 to maintain ,onsisten,y* >A) 0hat is a ,lusterin. inde/ ? $auses the data rows to be stored in the order s+e,ified in the inde/* A mandatory inde/ defined on a +artitioned table s+a,e* AD) How many ,lusterin. inde/es ,an be defined for a table? &nly one* A1) 0hat is the differen,e between +rimary =ey S uniOue inde/ ? <rimary F a relational database ,onstraint* <rimary =ey ,onsists of one or more ,olumns that uniOuely identify a row in the table* ;or a normaliEed relation? there is one desi.nated +rimary =ey* niOue inde/F a +hysi,al obNe,t that stores only uniOue values* %here ,an be one or more uniOue inde/es on a table*

A2) 0hat is sOl,ode -A22 ? AuthoriEation failure A-) 0hat is sOl,ode ->11? !"#"$% statement has resulted in retrieval of more than one row* A2) 0hat does the sOl,ode of ->1> +ertain to? %his is .enerated when the ,onsisten,y to=ens in the DB14 and the load module are different* A3) Are views u+dateable ? 'ot all of them* !ome views are u+dateable e*.* sin.le table view with all the fields or mandatory fields* "/am+les of non-u+dateable views are views whi,h are Noins? views that ,ontain a..re.ate fun,tions(su,h as 4I')? and views that have :1& < B7 ,lause* A6) If I have a view whi,h is a Noin of two or more tables? ,an this view be u+dateable? 'o* A8) 0hat are the 2 environments whi,h ,an a,,ess DB2 ? %!&? $I$!? I4! and BA%$H A>) 0hat is an inner Noin? and an outer Noin ? Inner MoinF ,ombine information from two or more tables by ,om+arin. all values that meet the sear,h ,riteria in the desi.nated ,olumn or ,olumns of on e table with all the ,lause in ,orres+ondin. ,olumns of the other table or tables* %his =ind of Noin whi,h involve a mat,h in both ,olumns are ,alled inner Noins* &uter Noin is one in whi,h you want both mat,hin. and non mat,hin. rows to be returned* DB2 has no s+e,ifi, o+erator for outer Noins? it ,an be simulated by ,ombinin. a Noin and a ,orrelated sub Ouery with a 'I&'* AA) 0hat is ;1""<A:" and <$%;1"" in %AB#"!<A$" ,reation? <$%;1""F +er,enta.e of ea,h +a.e to be left free ;1""<A:"F 'umber of +a.es to be loaded with data between ea,h free +a.e 1DD) 0hat are sim+le? se.mented and +artitioned table s+a,es ? !im+le %ables+a,eF $an ,ontain one or more tables 1ows from multi+le tables ,an be interleaved on a +a.e under the DBAs ,ontrol and maintenan,e !e.mented %ables+a,eF $an ,ontain one or more tables %ables+a,e is divided into se.ments of 2 to 62 +a.es in in,rements of 2 +a.es*

"a,h se.ment is dedi,ated to sin.le table* A table ,an o,,u+y multi+le se.ments <artitioned %ables+a,eF $an ,ontain one table %ables+a,e is divided into +arts and ea,h +art is +ut in a se+arate 9!A4 dataset* 1D1) 0hat is filter fa,tor? one divided by the number of distin,t values of a ,olumn* 1D2) 0hat is inde/ ,ardinality? %he number of distin,t values a ,olumn or ,olumns ,ontain* 1D-) 0hat is a synonym ? !ynonym is an alternate name for a table or view used mainly to hide the leadin. Oualifier of a table or view** A synonym is a,,essible only by the ,reator* 1D2) 0hat is the differen,e between !7'&'74 and A#IA!? !7'&'74F is dro++ed when the table or tables+a,e is dro++ed* !ynonym is available only to the ,reator* A#IA!F is retained even if table or tables+a,e is dro++ed* A#IA! ,an be ,reated even if the table does not e/ist* It is used mainly in distributed environment to hide the lo,ation info from +ro.rams* Alias is a .lobal obNe,t S is available to all* 1D3) 0hat do you mean by '&% ' ## 0I%H D";A #%? 0hen will you use it? %his ,olumn ,annot have nulls and while insertion? if no value is su++lied then it wil have Eeroes? s+a,es or dateGtime de+endin. on whether it is numeri,? ,hara,ter or dateGtime* se it when you do not want to have nulls but at the same time ,annot .ive values all the time you insert this row* 1D6) 0hat do you mean by '&% ' ##? 0hen will you use it? %he ,olumn ,annot have nulls* se it for =ey fields* 1D8) 0hen would you +refer to use 9A1$HA1? 0hen a ,olumn whi,h ,ontains lon. te/t? e*.* remar=s? notes? may have in most ,ases less than 3DJ of the ma/imum len.th* 1D>) 0hat are the disadvanta.es of usin. 9A1$HA1? 1* $an lead to hi.h s+a,e utiliEation if most of the values are ,lose to ma/imum* 2* <ositionin. of 9A1$HA1 ,olumn has to be done ,arefully as it has +erforman,e im+li,ations* -* 1elo,ation of rows to different +a.es ,an lead to more IG&s on retrieval* 1DA) How do I ,reate a table 4A'A:"1 ( "4<Q? 4A'A:"1) where 4A'A:"1 is a forei.n =ey whi,h referen,es to "4<Q in the same table? :ive the e/a,t

DD#* ;irst $1"A%" 4A'A:"1 table with "4<Q as the +rimary =ey* %hen A#%"1 it to define the forei.n =ey* 0hen is the authoriEation ,he,= on DB2 obNe,ts done - at BI'D time or run time? At run time* 11D) 0hat is auditin.? 1e,ordin. !Q# statements that a,,ess a table* !+e,ified at table ,reation time or throu.h alter*

Вам также может понравиться