DB2 - Perguntas e respostas


Volta a página anterior

Volta ao Menu Principal


Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

DB2 - Perguntas e respostas

Perguntas e respostas pesquisadas na internet. Com mais tempo, provavelmente, faremos a tradução para o português.

  1. Which is the most widely used batch performance monitor for DB2?
    Answer:
    • DB2PM

  2. Can I alter a table (like adding a column) when other user is selecting some columns or updating some columns from the same table?
    Answer:
    • Yes.
      It is possible until the updating or selection is committed, DB2 table will not be restructured.
      New column definition will be there but it will not be included until all the tasks on the table are committed.

  3. How many subqueries can you combine together ?
    Answer:
    • Total 16 queries and subqueries are 15

  4. What are the different methods of accessing DB2 from TSO? How is the connection established between TSO & DB2?
    Answer:
    • There are three ways in establishing TSO/DB2 connection 1. SPUFI
      2. QMF
      3. CATALOG VISIBILITY;
      A thread between TSO & DB2 is established while attempting to make connection between TSO & DB2.

  5. How many buffer bools are available in DB2?
    Answer:
    • Ten 32K size bufferpools and fifty 4K size buffer pools (BP0 to BP49).
      Default buffer pools are BP0, BP1, BP2 & BP32

  6. What is B37 abend during SPUFI?
    Answer:
    • The B37 ABEND in the SPUFI is because of space requirements.
      The query has resulted in so many rows that the SPUFI.OUT file is not large enough to handle it;
      One possible solution is to increase the space allocation of SPUFI.OUT file.

  7. What is the command used by TSO users to invoke DB2?
    Answer:
    • DSN RUN

  8. What is the error code -803 ?
    Answer:
    • Unique Index violation

  9. How do you filter out the rows retrieved from a DB2 table?
    Answer:
    • One way is to use the SQL WHERE clause.

  10. What is a collection?
    Answer:
    • A collection is something that every programmer should assign/specify for every package.
      This is about 1-18 characters long.

  11. What is Skeleton Cursor Table (SKCT)?
    Answer:
    • The Executable form of a Plan.
      This is stored in SYSIBM.SCT02 table.

  12. What is the equivalent Cobol Data type for Decimal (x,y) in DB2?
    What does the current SQLID register contain? Answer:
    • PIC S9(X-Y)V9(Y) COMP-3; The current SQLID contains the current authorization ID.

  13. Can we declare DB2 HOST variable in COBOL COPY book?
    Answer:
    • NO.
      If we declare DB2 host variable in COBOL COPY book, at the time of Pre-compilation we get the host variable not defined, because pre-compiler will not expand COBOL COPY book.
      So we declare it either in DCLGEN with EXEC SQL INCLUDE DCLGEN NAME END-EXEC or we directly hardcode it in the working storage section.

  14. What should be specified along with a cursor in order to continue updating process after COMMIT?
    Answer:
    • With Hold option.

  15. What is the name of the default DB2 catalog database?
    Answer:
    • DSNDB06

  16. When can you be sure that a query will return only one row?
    Answer:
    • When you use the primary key and only the primary key in the WHERE clause.

  17. What is the difference between JOIN and UNION?
    Answer:
    • JOIN is used to retrieve data from different tables using a single SQL statement.
      UNION is used to combine the results of two or more SQL queries.

  18. What is a correlated subquerry?
    Answer:
    • In a subquerry, if the outer query refers back to the outcome of inner query it is called correlated subquerry.
      That's why the outer query is evaluated first unlike an ordinary subquerry

  19. What are the functions of Bind?
    Answer:
    • BIND mainly performs two things: Syntax checking and Authorization checking.
      It binds together all packages into an application plan hence the name BIND.
      Apart from this bind has optimizer as a subcomponent. Its function is to determine the optimum access strategy.

  20. What is an intent lock?
    Answer:
    • An intent lock is at the table level for a segmented table space or at the table space level for a non segmented table space They indicate at the table or table space level the kinds of locks at lower levels.

  21. What is the difference between Static and Dynamic SQL?
    Answer:
    • Static SQL is hard-coded in a program when the programmer knows the statements to be executed For dynamic SQL the program must dynamically allocate memory to receive the query results.

  22. What is cursor stability?
    Answer:
    • Cursor stability means that DB2 takes a lock on the page the cursor is accessing and releases the lock when the cursor moves to another page.

  23. What is the significance of the CURSOR WITH HOLD clause in a cursor declaration?
    Answer:
    • The clause avoids closing the cursor and repositioning it to the last row processed when the cursor is reopened.

  24. What is the SQL Communications Area and what are some of its key fields?
    Answer:
    • It is a data structure that must be included in any host-language program using SQL It is used to pass feedback about the SQL operations to the program Fields are return codes, error messages, Handling codes and warnings.

  25. What is the purpose of the WHENEVER statement?
    Answer:
    • The WHENEVER statement is coded once in the host program to control program actions depending on the SQL-CODE returned by each SQL statement within the program.

  26. What is DCLGEN?
    Answer:
    • A DCLGEN stands for declarations generator; it is a facility to generate DB2 SQL data structures in COBOL or PL/1 programs.

  27. What is the FREE command?
    Answer:
    • The FREE command can be used to delete plans and/or packages no longer Needed.

  28. DB2 can implement a join in three ways using a merge join, a nested join or a hybrid join Explain the differences.
    Answer:
    • A merge join requires that the tables being joined be in a sequence; the rows are retrieved with a high cluster ratio index or are sorted by DB2 A nested join does not require a sequence and works best on joining a small number of rows DB2 reads the outer table values and each time scans the inner table for matches The hybrid join is a nested join that requires the outer table be in sequence.

  29. Compare a sub select to a join.
    Answer:
    • Any sub select can be rewritten as a join, but not vice versa Joins are usually more efficient as join rows can be returned immediately, sub selects require a temporary work area for inner selects results while processing the outer select.

  30. What is the difference between IN sub selects and EXISTS sub select?
    Answer:
    • If there is an index on the attributes tested an IN is more efficient since DB2 uses the index for the IN (IN for index is the mnemonic).

  31. What is a Cartesian product?
    Answer:
    • A Cartesian product results from a faulty query It is a row in the results for every combination in the join tables.

  32. What is the difference between a package and a plan?
    Answer:
    • How does one bind 2 versions of a CICS transaction with the same module name in two different CICS regions that share the same DB2 subsystem?
      Package and plan are usually used synonymously as in this site Both contain optimized code for SQL statements - a package for a single program, module or subroutine contained in the data base request module (DBRM) library A plan may contain multiple packages and pointers to packages The one CICS module would then exist in a package that could be referenced in two different plans.

  33. What is an asychronous write?
    Answer:
    • It is a write to disk that may occur before or long after a commit The write is controlled by the buffer manager.

  34. What is a lock?
    Answer:
    • A lock is the mechanism that controls access to data pages and table spaces.

  35. What is meant by isolation level?
    Answer:
    • This is a key concept for any relational database Isolation level is the manner in which locks are applied and released during a transaction For DB2 a 'repeatable read' holds all locks until the Transaction completes or a sync point is issued.
      For transactions using 'cursor stability' the page lock releases are issued as the cursor 'moves', ie as the transaction releases address ability to the records.

  36. Describe EXPLAIN in DB2
    Answer:
    • EXPLAIN is used to detail the access paths chosen by DB2 optimizer for SQL statement.
      This command is used to monitor the performance of SQL statement used in a program.

  37. What do you mean by a BIND in DB2?
    Answer:
    • BIND mainly performs two things syntax checking and authorization checking.
      It binds together all packages into an application plan hence the name BIND.Apart from this bind has optimiser as a subcomponent.
      Its function is to determine the optimum access strategy.

  38. What is the maximum no of rows per page in DB2?
    Answer:
    • The maximum is 255

  39. What is the only place of VSAM KSDS in DB2?
    Answer:
    • BSDS is a VSAM KSDS.

  40. Does all users have the privilege to use the SQL statement SELECT * (DML)?
    Answer:
    • No the user should be given the GRANTED privilege to use it.

  41. Can you tell what is the size of a data page in DB2?
    Answer:
    • The size of the data page is 4K to 32K.

  42. What is the best locksize that you use when you create a tablespace in DB2?
    Answer:
    • The answer is Locksize = ANY.
      Unless you are completely sure what is the purpose of tablespace ie.,Read-only or R/W.
      If you use lock size =any, Db2 would automatically determine what type of locks it should use.

  43. Name the error code for Unique Index Violation in DB2?
    Answer:
    • The error code is -803.

  44. If the table size less than 10 PAGES, can you define an Index ?
    Answer:
    • No you cannot define an index.

  45. What is the Maximum Length of SQLCA and what is the content of SQLCABC in DB2?
    Answer:
    • The Max length is 136.
      And the SQLCABC has the Value of SQLCA.

  46. Can you tell what is the maximum number of characters that a tablename can have?
    Answer:
    • 18 characters.

  47. What is the max number of volumes that can be added to a STOGROUP in DB2?
    Answer:
    • The answer is 133.
      Usually it will be difficult monitor more than 3 or 4 volumes to a Stogroup.

  48. Explain -805 sql return code?
    Answer:
    • Program name not in plan. Bind the plan and include the DBRM for the program named as part of the plan.

  49. Tell me the usage of DSNDB07 ?
    Answer:
    • This is the area where sorting takes place in DB2

  50. When you are using cursor in the application programming, when does the SQL statement gets executed ?
    Answer:
    • SQL statement gets executed when we open cursor

  51. What is the use of CURRENTDATA in bind?
    Answer:
    • CURRENTDATA option ensures block fetch while selecting rows from a table.
      In DB2V4 the default has been changed to NO.
      Therefore it is necessary to change all the bind cards with CURRENTDATA(YES) which is default in DB2V3 & earlier to CURRENTDATA(NO).

  52. Differentiate between TYPE 1 index & TYPE 2 index.
    Answer:
    • TYPE 1 & TYPE 2 are specified when an index is created on the table.
      TYPE 2 index is the option which comes with DB2V4.
      With TYPE 2 index data can be retreived faster as only the data pages are locked and not the index pages.
      As such, TYPE 2 index is recommended.

  53. Explain what are the levels of isolation available with DB2V4.
    Answer:
    • CS RR UR ( added new for DB2V4 which stands for un-commited read which allows to retrieve records from the space which has exclusive locks also but data integrity will be affected if this option is used ).
      The best available option for data integrity & data concurrency is CS.

  54. Explain in brief how do you achieve record level locking in DB2 versions when record level locking is not allowed?<
    Answer:
    • By having the length of the record greater than that of a page.

  55. Can you tell how to define the data items to receive the fetch items for the SQL?
    Answer:
    • Using the DSECT, followed by lines of - 'dataitems DS datatype'.

  56. Explain how will you delete duplicate records from a table in DB2?
    Answer:
    • Delete From Table1Where Id In (Select Id From Tabel1 As Temp Group By Id Having Count(*) >1)

  57. Explian the difference between Where and Having Clause
    Answer:
    • The clause WHERE is for Rows and HAVING is for Groups.

  58. How can you view the structure of DB2 table?
    Answer:
    • By using QMF.

  59. Can you tell what is the max number of tables that can be stored on a Partitioned Table Space ?
    Answer:
    • Only one

  60. List the different types of Table spaces in DB2
    Answer:
    • The different types of tablespaces in DB2 are cited below.
      1. Simple Table Space
      2. Segmented Table Space and
      3. Partitioned Table Space.

  61. What are the max. & min. no. of partitions allowed in a partition tablespace?
    Answer:
    • Minimum is 4.
      Maximum is 64.

  62. What is the maximum number of tables that can be joined ?
    Answer:
    • Fifteen

  63. What technique is used to retrieve data from more than one table in a single SQL statement?
    Answer:
    • The Join statement combines data from more that two tables

  64. What is a foreign key?
    Answer:
    • It identifies a releated row in another table and establishes a logical relationship between rows in two tables.

  65. Explain the use of the WHERE clause.
    Answer:
    • It directs DB2 to extract data from rows where the value of the column is the same as the current value of the host variable.

  66. How would you find out the total number of rows in a table?
    Answer:
    • Use SELECT COUNT(*)<

  67. How do you eliminate duplicate values in SELECT?
    Answer:
    • Use SELECT DISTINCT

  68. How do you select a row using indexes?
    Answer:
    • Specify the indexed columns in the WHERE clause

  69. What are aggregate functions?
    Answer:
    • Built-in mathematical functions for use in SELECT clause

  70. How do you find the maximum value in a column?
    Answer:
    • Use SELECT MAX

  71. Can you use MAX on a CHAR column?
    Answer:
    • Yes

  72. My SQL statement SELECT AVG(SALARY) FROM EMP yields inaccurate results Why?
    Answer:
    • ecause SALARY is not declared to have NULLs and the employees for whom the salary is not known are also counted

  73. How do you retrieve the first 5 characters of FIRSTNAME column of EMP table?
    Answer:
    • SELECT SUBSTR(FIRSTNAME,1,5) FROM EMP;

  74. How do you concatenate the FIRSTNAME and LASTNAME from EMP table to give a complete name?
    Answer:
    • SELECT FIRSTNAME || LASTNAME FROM EMP;

  75. What is the use of VALUE function?
    Answer:
    • Avoid -ve SQL CODE by handling nulls and zeroes in computations Substitute a numeric value for any nulls used in computation


  76. What is UNION,UNION ALL?
    Answer:
    • UNION : eliminates duplicates
      UNION ALL: retains duplicates
      Both these are used to combine the results of different SELECT statements

  77. Suppose I have five SQL SELECT statements connected by UNION/UNION ALL, how many times should I specify UNION to eliminate the duplicate rows?
    Answer:
    • Once

  78. What is the restriction on using UNION in embedded SQL?
    Answer:
    • It has to be in a CURSOR

  79. In the WHERE clause what is BETWEEN and IN?
    Answer:
    • BETWEEN supplies a range of values while IN supplies a list of values

  80. Is BETWEEN inclusive of the range values specified?
    Answer:
    • Yes

  81. What is 'LIKE' used for in WHERE clause?What are the wildcard characters?
    Answer:
    • LIKE is used for partial string matches '%' ( for a string of any character ) and '_' (for any single character ) are the two wild card characters

  82. When do you use a LIKE statement?
    Answer:
    • To do partial search eg to search employee by name, you need not specify the complete name; using LIKE, you can search for partial string matches

  83. What is the meaning of underscore ( '_' ) in the LIKE statement?
    Answer:
    • Match for any single character

  84. What do you accomplish by GROUP BY HAVING clause?
    Answer:
    • GROUP BY partitions the selected rows on the distinct values of the column on which you group by HAVING selects GROUPs which match the criteria specified.
      Consider the employee table with column PROJECT nullable How can you get a List of employees who are not assigned to any project?
      SELECT EMPNO FROM EMP WHERE PROJECT IS NULL;
      What is the result of this uery if no rows are selected:
      SELECT SUM(SALARY) FROM EMP WHERE UAL='MSC'; NULL

  85. Why SELECT * is not preferred in embedded SQL programs?
    Answer:
    • For three reasons: If the table structure is changed ( a field is added ), the program will have to be modified Program might retrieve the columns which it might not use, leading on I/O over head The chance of an index only scan is lost

  86. What are correlated sub queries?
    Answer:
    • A sub-query in which the inner ( nested ) query refers back to the table in the outer query Correlated Sub queries must be evaluated for each qualified row of the outer query that is referred to.

  87. What is a CURSOR?
    Why should it be used?
    Answer:
    • Cursor is a programming device that allows the SELECT to find a set of Rows but return them one at a time Cursor should be used because the host language can deal with only one row at a time

  88. What are leaf pages?
    Answer:
    • They are the opposite of root pages Leaf pages are the lowest level index pages - the pages that contain index entries and information to the corresponding table rows.

  89. What is a pre-compiler?
    Answer:
    • It is a DB2 facility for static SQL statements - it replaces these statements with calls to the DB2 language interface module.

  90. What is a root page?
    Answer:
    • The opposite of a leaf page; it is the highest level index page An index can contain only the one root page; all other index pages are associated to the root.

  91. What is a thread?
    Answer:
    • A thread is the connection between DB2 and some other subsystem, such as CICS or IMS/DC.

  92. What is Bind ?
    What are the different bind parameters ?
    Answer:
    • Bind is a process where the DBRM'S are converted into a Plan which is an executable module containing the access path logic produced by the DB2 optimizer.
      It also does syntax checking of the SQL code in the DBRM'S and authorization checking.
      PLAN NAME - Name of the plan
      ACTION ON PLAN - ADD or REPLACE.
      This parameter controls whether the existing plan will be replaced by the newly built plan (with this bind) or a new plan will be created.
      RETAIN - To retain or not the old authorities.
      The retain specification makes DB2 decide whether the authorizations of the user who did the previous BIND of the plan will be retained for the new plan.
      ISOLATION LEVEL - CS and RR
      This parameter helps DB2 in deciding the duration of PAGE LOCKS required by the application program.
      VALIDATION - RUN or BIND. To tell whether authorization will be checked at rou or bind time.
      ACQUIRE - USE or ALLOCATE.
      This parameter controls the table space to be maintained over the resource used by the program.
      It decides the duration for which these locks should be held
      RELEASE - COMMIT or DEALLOCATE
      This parameter specifies to DB2 when the table space locks ACQUIRED earlier by the program should be RELESED EXPLAIN - YES or NO OWNER - AUTH ID - primary authorization. PREPARE - YES or NO.


  93. What is Rebind and Bind (replace)?
    Answer:
    • Rebind has to be done if the plan o r package is invalid.

  94. What is an index ?
    What for it is ? Answer:
    • An index is an ordered set of pointers to the data in the DB2 table, stored separately from the table.
      This is used to improve performance and ensure uniqueness (only for unique index) .

  95. How many indexes can be built on a table ?
    How many clustering indexes can be built on a table ?
    Answer:
    • Only one.

  96. What is a clustering index ?
    What is REORG ?
    Its uses ? When will we do REORG ?
    Answer:
    • Clustering index causes the data rows to be stored in the order specified in the index. A mandatory index defined on a partitioned table space.
      Only one clustering indexes can be defined for a table.
      REORG reorganizes data on physical storage to re-cluster rows, positioning overflowed rows in their proper sequence, to reclaim space, to restore free space.
      It is used after heavy updates, inserts and deletes activity and after segments of a segmented tables space have became fragmented.

  97. What is a filter factor?
    Answer:
    • For a table space scan , the FF Should be high or low?
      Filter Factor is one divided by the number of distinct values of a column?
      Filter Factors eliminate non-qualifying rows from the estimate of the access cost for the various access methods.
      Usually, only a subset of rows will qualify to be returned for each particular predicate on the WHERE clause.
      The lower the filter factor for a given predicate, the more likely DB2 will choose that predicate's access path for the plan, assuming it participates in an index.
      Every predicate has a filter factor, and these values are used to calculate QCARD and DMCARD for the SQL statement;
      that is, the number of rows returned to the user (query cardinality) and the number of Stage 1 calls (Data Manager cardinality).
      The ultimate purpose of applying the filters is to estimate the number of rows Returned.


  98. What is RUNSTATS?
    When will you do this? After RUNSTATS what will you do?
    Answer:
    • A DB2 utility used to collect statistics about the data values in tables which can be used by the optimizer to decide the access path.
      It also collects statistics used for space management.
      These statistics are stored in DB2 catalog tables.
      After a load, or after mass updates, inserts, deletes, or after REORG we will chose to run RUNSTATS.
      Some example of statistics collected during RUNSTARTS # of rows in the table Percent of rows in clustering sequence # of distinct values of indexed column # of rows moved to a nearby/faraway page due to row length increase.

  99. What is 'explain' command?
    Answer:
    • EXPLAIN is used to display the access path as determined by the optimizer for a SQL stmt .
      It can be used in SPUFI(for single SQL statement) or in BIND step(for embedded SQL).

  100. What is an indicator variable?
    Answer:
    • An Indicator variable is a small integer used to indicate whether its associated host variable is null.

  101. How do you declare an indicator variable?
    Answer:
    • An Indicator variable is preceded by a colon(:) and coded immediately after the host variable.
      The variable has to be declared in the working storage section.
      Example: :DEPT:DEPT-IND Where DEPT-IND is an Indicator variable.

  102. Where do you declare the cursor in program?
    Answer:
    • WORKING-STORAGE SECTION, LOCAL-STORAGE SECTION.

  103. What is 'with hold' option in cursor?
    Answer:
    • At the end of a Commit or Rollback the cursor will be closed and has to be reopened again.
      If we want the cursor to be opened even after the Commit or Rollback, 'with hold' option has to specified on the Declare cursor statement.
      Example:
      DECLARE DEPTCUR CURSOR WITH HOLD FOR SELECT EMPNO, ENAME, SALARY FROM EMPTABLE FOR UPDATE OF SALARY
      Cannot be used in programs that are not pseudo conversational.

  104. Can we update/delete via a cursor?
    What are the restrictions on this?
    Answer:
    • Update / delete is possible via cursor.
      Only the current row is updated/deleted.

  105. When, views are not up-datable ?
    Answer:
    • Non-up-datable views are views which are joins, views that contain aggregate functions (such as MIN), and views that have GROUP BY clause.
      Some views are up-datable ex: single table view with all the fields or mandatory fields.

  106. What is a correlated sub query?
    Answer:
    • A sub-query in which the (nested) inner query refers back to the table in the outer query.
      Correlated sub-queries must be evaluated for each qualified row of the outer query that is referred to.
    What is normalization and what are the five normal forms?

  107. Answer:
    • Normalization is a design procedure for representing data in tabular format.
      The five normal forms are progressive rules to represent the data with minimal redundancy.

  108. What techniques are used to retrieve data from more than one table in a single SQL statement?
    Answer:
    • Joins, unions and nested selects are used to retrieve data.

  109. What are the different data types in DB2?
    Answer:
    • Smallint
      Integer
      DECIMAL
      FLOAT
      Character, Varcharacter
      Graphic, Vargraphic
      Date
      Time
      Timestamp

  110. What is a view ?
    What are the advantages and restrictions of using a view ?
    Answer:
    • A view is a virtual table derived from one or more base tables.
      It prevents unauthorized users from having access to sensitive data.
      Cannot insert, delete or update a view, which is based on more than one base table.

  111. What do you mean by referential Integrity?
    Answer:
    • Referential integrity is a condition wherein all references from one table to another are valid.
      It is the enforcement of all referential constraints(a rule that the value of a foreign key must appear as the value of a primary key of some other specific table.)

  112. What is a Subquery ?
    Answer:
    • A subquery is a query that is written as part of another query's WHERE clause.

  113. What is corrleated subquery ?
    Answer:
    • A correlated subquery is one that has a correlation name as a table or view designator in the FROM clause of the outer query and the same correlation name as qualifier of a search condition in the WHERE clause of the subquery.

  114. How does the processing of correlated subquery differ from a noncorrelated ?
    Answer:
    • The subquery in a correlated subquery is reevaluated for every row of the table or view named on the outer query, while the subquery Of a noncorrelated subquery is evaluated only once.

  115. What is DB2 bind ?
    Answer:
    • A bind is a process that builds 'access paths' to DB2 tables.
      A bind uses the Database Request module(s) from the DB2 precompile step as input and produces an application plan.
      It also checks the user's authority and validates the SQL Statements in the DBRM.

  116. What is a plan?
    Answer:
    • A plan in db2 produced during the bind process.
      One or more database request modules with a plan name.

  117. What is a synonym?
    How is it used?
    Answer:
    • A synonym is used to reference a table or view by another name.
      The other name can then be written in the application code pointing to test tables in the development stage and to production entities when the code is migrated.
      The synonym is linked to the AUTHID that created it.

  118. What is an alias and how does it differ from a synonym?
    Answer:
    • An alias is an alternative to a synonym, designed for a distributed environment to avoid having to use the location qualifier of a table or view.
      The alias is not dropped when the table is dropped.

  119. Describe the primary key and the foreign key?
    Answer:
    • The primary key is a column or a set of columns that provide a unique identifier to each row of a table.
      The foreign key is a column or a set of columns that refers to the primary key of another table.

  120. What is DDL and DML?
    Answer:
    • DDL - Data Definition Language (CREATE, ALTER, TRUNCATE)
      DML - Data Manipulation Language (SELECT, INSERT, DELETE & UPDATE)

  121. What is DCLGEN?
    Answer:
    • DCLGEN stands for declarations generator; it is a facility to generate DB2 sql data structures in COBOL or PL/I programs.

  122. What is the significance of the CURSOR WITH HOLD clause in a cursor declaration?
    Answer:
    • The clause avoids closing the cursor and repositioning it to the last row processed when the cursor is reopened.

  123. What are the three lock types?
    Answer:
    • The three types are shared, update and exclusive.
      Shared locks allow two or more programs to read simultaneously but not change the locked space.
      An exclusive lock bars all other users from accessing the space.
      An update lock is less restrictive; it allows other transactions to read or acquire shared locks on the space.

  124. What is deadlock ?
    Answer:
    • Deadlock occurs when transactions executing at the same time lock each other out of data that they need to complete their logical units of work.

  125. What is the difference between group by and order by ?
    Answer:
    • Group by controls the presentation of the rows, order by controls the presentation of the columns for the results of the SELECT statement.

  126. What is a clustered index ?
    Answer:
    • For a clustered index DB2 maintains rows in the same sequence as the columns in the index for as long as there is free space.
      DB2 can then process that table in that order efficiently.

  127. What is the equivalent cobol definiton for the datatypes in DB2 ?
    Answer:
    • Smallint - S9(4) COMP or S9(4) COMP-4
      Integer - S9(9) COMP or S9(9) COMP-4
      Char(N) - PIC X(N)
      Varchar(N) - 01 NAME.
      49 NAME-LEN PIC S9(4) USAGE COMP.
      49 NAME-TEXT PIC X(N).
      DECIMAL(P,S)


  128. How do you add columns to an existing table ?
    Answer:
    • ALTER table command can be used to add columns to an existing table.

  129. How would you retrieve rows from a DB2 table in embedded SQL?
    Answer:
    • Either by using the single row SELECT statements, or by using the CURSOR

  130. Apart from cursor, what other ways are available to you to retrieve a row from a table in embedded SQL?
    Answer:
    • Single row SELECTs

  131. How do you specify and use a cursor in a COBOL program?
    Answer:
    • Use DECLARE CURSOR statement either in working storage or in procedure division (before open cursor), to specify the SELECT statement Then use OPEN, FETCH rows in a loop and finally CLOSE

  132. What happens when you say OPEN CURSOR?
    Answer:
    • If there is an ORDER BY clause, rows are fetched, sorted and made available for the FETCH statement Other wise simply the cursor is placed on the first row

  133. Is DECLARE CURSOR executable?
    Answer:
    • No

  134. Can you have more than one cursor open at any one time in a program?
    Answer:
    • Yes

  135. When you COMMIT, is the cursor closed?
    Answer:
    • Yes

  136. How do you leave the cursor open after issuing a COMMIT?
    Answer:
    • (for DB2 23 or above only)
      Use WITH HOLD option in DECLARE CURSOR statement But, it has not effect in psuedo-conversational CICS programs


  137. Answer:

  138. Give the COBOL definition of a VARCHAR field
    Answer:
    • A VARCHAR column REMARKS would be defined as follows:
      10 REMARKS
      49 REMARKS-LEN PIC S9(4) USAGE COMP
      49 REMARKS-TEXT PIC X(1920)


  139. What is the physical storage length of each of the following DB2 data types:
    Answer:
    • DATE, TIME, TIMESTAMP and its picture clause in COBOL.
      DATE: 4bytes DATE: PIC X(10)
      TIME: 3bytes TIME PIC X(08)
      TIMESTAMP: 10bytes
      TIMESTAMP: PIC X(26)

  140. What is the COBOL picture clause for a DB2 column defined as DECIMAL(11,2)?
    Answer:
    • PIC S9(9)V99 COMP-3
      Note: In DECIMAL(11,2), 11 indicates the size of the data type and 2 indicates the precision

  141. Is DECLARE TABLE in DCLGEN necessary?
    Why it used?
    Answer:
    • It not necessary to have DECLARE TABLE statement in DCLGEN This is used by the pre-compiler to validate the table-name, view-name, column name etc, during pre-compile.


  142. Will pre-compile of an DB2-COBOL program bomb, if DB2 is down?
    Answer:
    • No Because the pre-compiler does not refer to the DB2 catalogue tables

  143. How is a typical DB2 batch Program gm executed ?
    Answer:
    • Use DSN utility to run a DB2 batch program from native TSO An example is shown: DSN SYSTEM(DSP3) RUN PROGRAM(EDD470BD) PLAN(EDD470BD) LIB('ED01TOBJLOADLIB') END Use IKJEFT01 utility program to run the above DSN command in a JCL

  144. Assuming that a site's standard is that pgm name = plan name, what is the easiest way to find out which pgms are affected by change in a table's structure ? Answer:
    • Query the catalogue tables SYSPLANDEP and SYSPACKDEP

  145. Name some fields from SQLCA.
    Answer:
    • SQLCODE, SQLERRM, SQLERRD

  146. How can you Quickly find out the # of rows updated after an update statement?
    Answer:
    • Check the value stored in SQLERRD(3)

  147. What do you need to do before you do EXPLAIN?
    Answer:
    • Make sure that the PLAN_TABLE is created under the AUTHID

  148. Where is the output of EXPLAIN stored?
    Answer:
    • In userid PLAN_TABLE

  149. EXPLAIN has output with MATCHCOLS = 0 What does it mean?
    Answer:
    • A non matching index scan if ACCESSTYPE = I

  150. How do you do the EXPLAIN of a dynamic SQL statement?
    Answer:
    • 1. Use SPUFI or MF to EXPLAIN the dynamic SQL statement
      2. Include EXPLAIN command in the embedded dynamic SQL statements

  151. How do you simulate the EXPLAIN of an embedded SQL statement in SPUFI/MF? Give an example with a host variable in WHERE clause?
    Answer:
    • Use a Question mark in place of a host variable ( or an unknown value ) eg SELECT EMP_NAME FROM EMP WHERE EMP_SALARY > N

  152. What are the isolation levels possible ?
    Answer:
    • CS: Cursor Stability
      RR: Repeatable Read

  153. What is the difference between CS and RR isolation levels?
    Answer:
    • CS: Releases the lock on a page after use
      RR: Retains all locks acquired till end of transaction

  154. Where do you specify them ?
    Answer:
    • ISOLATION LEVEL is a parameter for the bind process

  155. When do you specify the isolation level? How?
    Answer:
    • During the BIND process ISOLATION ( CS/RR )

  156. I use CS and update a page Will the lock be released after I am done with that page?
    Answer:
    • No

  157. What are the various locking levels available?
    Answer:
    • PAGE, TABLE, TABLESPACE

  158. How does DB2 determine what lock-size to use?
    Answer:
    • 1. Based on the lock-size given while creating the tablespace
      2. Programmer can direct the DB2 what lock-size to use
      3. If lock-size ANY is specified, DB2 usually choses a lock-size of PAGE

  159. What are the disadvantages of PAGE level lock?
    Answer:
    • High resource utilization if large updates are to be done.

  160. What is SPUFI & QMF ?
    Answer:
    • SPUFI - Sql Processing Using File Input
      QMF - Query Management Facility
      Both of them are DB2 interactive menu-driven tools used by developers to create & modify database objects.

  161. Q2 - Name a few utilities available in DB2 ?
    Answer:
    • LOAD
      MERGE
      MODIFY
      QUIESCE
      REBUILD
      RECOVER
      REORG
      REPORT
      REPAIR
      RUNSTATS

    What are the different COLUMN functions ?

  162. Answer:
    • SUM - Returns the total value.
      MIN - Returns the minimum value.
      AVG - Returns the average value.
      MAX - Returns the maximum value.
      COUNT - Returns the number of selected rows.
      STDDEV - Returns the standard deviation of the column values.
      VARIANCE - Returns the variance of the column values.

  163. What is a scalar function ?
    Answer:
    • A scalar function also produces a single value, but unlike the argument of a column function, an argument of a scalar function is a single value.

  164. What is a COLUMN function ?
    Answer:
    • A column function produces a single value for a group of rows.
      You can use the SQL column functions to calculate values based on entire columns of data.
      The calculated values are from selected rows only (all rows that satisfy the WHERE clause).

  165. What are the different types of Table spaces ?
    Answer:
    • Simple Table Space
      Segmented Table Space
      Partitioned Table Space

  166. What is Cursor Stability(CS) ?
    Answer:
    • A page lock is held only while the cursor is positioned on that page.
      When the cursor moves to another page, the lock is released.
      When a page is locked concurrent application programs cannot update or delete a row of the locked page.
      The current lock is not released until a new lock is acquired.
      If an application program updates or deletes data, the lock is held until the data is committed.
      CS applies only to data that is read.
      All changed data remains locked until COMMIT or ROLLBACK.

  167. What is the purpose of a null indicator variable? and what are the possible values in the variable and what do they mean ?
    Answer:
    • A Null Indicator is used to indicate whether the host variable has been assigned a null.
      It used to indicate whether a retrieved character value has been truncated.
      It is used to set a column to null.
      The indicator value of:
      -1 means the associated host variable contains null.
      0 (zero) means the associated host variable does not contain null, nor the returned value is truncated.
      -2 means the associated host variable contains null due to a numeric or arithmetic conversion error.
      >0 means the value assigned to the host variable is truncated.
      The value represented by the indicator variable is the actual length of the character value before truncation.

  168. What is commit and rollback ?
    Answer:
    • A commit occurs automatically at the end of the program, or by request one or more times during the execution of the program.
      Releases all locks acquired by the program since the last commit, so that other programs and users may obtain access to the data.
      Any open cursors are automatically closed. All database changes are made permanent.
      If any changes made to the tables are not appropriate, then all the changes must by rolled back resulting in the same state of data as they were prior to making changes.
      Release all locks acquired by the program.


  169. What is the self-referencing constraint?
    Answer:
    • The self-referencing constraint limits in a single table the changes to a primary key that the related foreign key defines.
      The foreign key in a self referencing table must specify the DELETE CASCADE rule.

  170. What are delete-connected tables?
    Answer:
    • Tables related with a foreign key are called delete-connected because a deletion in the primary key table can affect the contents of the foreign key table.

  171. When can an insert of a new primary key value threaten referential integrity?
    Answer:
    • Never.
      New primary key values are not a problem.
      However, the values of foreign key inserts must have corresponding primary key Values in their related tables.
      And updates of primary key values may require changes in foreign key values to maintain referential integrity.

  172. In terms of DB2 indexing, what is the root page?
    Answer:
    • The simplest DB2 index is the B-tree and the B-tree's top page is called the root page.
      The root page entries represent the upper range limits of the index and are referenced first in a search.

  173. How does Db2 use multiple table indexes?
    Answer:
    • DB2 use the multiple indexes to satisfy multiple predicates in a SELECT statement that are joined by an AND or OR.

  174. What are some characteristics of columns that benefit from indexes?
    Answer:
    • Primary key and foreign key columns; Columns that have unique values; columns that have aggregates computed frequently and columns used to test the existence of a value.

  175. What is a composite index and how does it differ from a multiple index?
    Answer:
    • A multiple index is not one index but two indexes for two different columns of a table.
      A composite index is one index made up of combined values from two columns in a table.
      If two columns in a table will often be accessed together a composite index will be efficient.

  176. What is meant by index cardinality?
    Answer:
    • The number of distinct values for a column is called index cardinality.
      DB2's RUNSTATS utility analyzes column value redundancy to determine whether to use a tablespace or index scan to search for data.

  177. What is a clustered index?
    Answer:
    • For a clustered index DB2 maintains rows in the same sequence as the columns in the index for as long as there is free space.
      DB2 can then process that table in that order efficiently.

  178. What keyword does an SQL SELECT statement use for a string search?
    Answer:
    • The LIKE keyword allows for string searches.
      The % sign is used as a wildcard.

  179. What are some sql aggregates and other built-in functions?
    Answer:
    • The common aggregate, built-in functions are AVG, SUM, MIN, MAX, COUNT and DISTINCT.

  180. How is the SUBSTR keyword used in sql?
    Answer:
    • SUBSTR is used for string manipulation with column name, first position and string length used as arguments. Eg. SUBSTR (NAME, 1 3) refers to the first three characters in the column NAME.

  181. What are the three DB2 date and time data types and their associated functions? Answer:
    • The three data types are DATE, TIME and TIMESTAMP.
      CHAR can be used to specify the format of each type.
      The DAYS function calculates the number of days between two dates.
      (It's Y2K compliant).

  182. Explain transactions, commits and rollbacks in DB2.
    Answer:
    • In DB2 a transaction typically requires a series of updates, insertions and deletions that represent a logical unit of work.
      A transaction puts an implicit lock on the DB2 data.
      Programmers can use the COMMIT WORK statement to terminate the transaction creating smaller units for recovery.
      If the transaction fails DB2 uses the log to roll back values to the start of the transaction or to the preceding commit point.

  183. What is deadlock?
    Answer:
    • Deadlock occurs when transactions executing at the same time lock each other out of data that they need to complete their logical units of work.

  184. What are the four lockable units for DB2?
    Answer:
    • DB2 imposes locks of four differing sizes: pages, tables, tablespace and for indexes subpage.

  185. What are the three lock types?
    Answer:
    • The three types are shared, update and exclusive.
      Shared locks allow two or more programs to read simultaneously but not change the locked space.
      An exclusive lock bars all other users from accessing the space.
      An update lock is less restrictive; it allows other transactions to read or acquire shared locks on the space.

  186. What is isolation level?
    Answer:
    • SQL statements may return any number of rows, but most host languages deal with one row at a time by declaring a cursor that presents each row at a unique isolation level.

  187. What is an intent lock?
    Answer:
    • An intent lock is at the table level for a segmented tablespace or at the tablespace level for a nonsegmented tablespace.
      They indicate at the table or tablespace level the kinds of locks at lower levels.

  188. What is the significance of the CURSOR WITH HOLD clause in a cursor declaration?
    Answer:
    • The clause avoids closing the cursor and repositioning it to the last row processed when the cursor is reopened.

  189. What is the SQL Communications Area and what are some of its key fields?
    Answer:
    • It is a data structure that must be included in any host-language program using SQL.
      It is used to pass feedback about the sql operations to the program.
      Fields are return codes, error messages, handling codes and warnings.

  190. What is the purpose of the WHENEVER statement? Answer:
    • The WHENEVER statement is coded once in the host program to control program actions depending on the SQL-CODE returned by each sql statement within the program.

  191. What is the FREE command?
    Answer:
    • The FREE command can be used to delete plans and/or packages no longer needed.

  192. DB2 can implement a join in three ways using a merge join, a nested join or a hybrid join.
    Explain the differences.
    Answer:
    • A merge join requires that the tables being joined be in a sequence; the rows are retrieved with a high cluster ratio index or are sorted by DB2.
      A nested join does not require a sequence and works best on joining a small number of rows.
      DB2 reads the outer table values and each time scans the inner table for matches.
      The hybrid join is a nested join that requires the outer table be in sequence.

  193. Compare a subselect to a join.
    Answer:
    • Any subselect can be rewritten as a join, but not vice versa.
      Joins are usually more efficient as join rows can be returned immediately, subselects require a temporary work area for inner selects results while processing the outer select.

  194. What is the difference between IN subselects and EXISTS subselect?
    Answer:
    • If there is an index on the attributes tested an IN is more efficient since DB2 uses the index for the IN.
      (IN for index is the mnemonic).

  195. What is an asychronous write?
    Answer:
    • It is a write to disk that may occur before or long after a commit.
      The write is controlled by the buffer manager.

  196. What is a lock?
    Answer:
    • A lock is the mechanism that controls access to data pages and tablespaces.

  197. What are leaf pages?
    Answer:
    • They are the opposite of root pages.
      Leaf pages are the lowest level index pages - the pages that contain index entries and information to the corresponding table rows.

  198. What is a LIKE table and how is it created?
    Answer:
    • A LIKE table is created by using the LIKE parameter in a CREATE table statement LIKE tables are typically created for a test environment from the production Environment.

  199. If the base table underlying a view is restructured, eg attributes are added, does the application code accessing the view need to be redone?
    Answer:
    • No. The table and its view are created anew, but the programs accessing the view do not need to be changed if the view and attributes accessed remain the same.
      Under what circumstances will DB2 allow an SQL statement to update more than one primary key value at a time?
      Never Such processing could produce duplicate values violating entity integrity Primary keys must be updated one at a time
      What is the cascade rule and how does it relate to deletions made with a Sub Select?
      The cascade rule will not allow deletions based on a Sub Select that references the same table from which the deletions are being made.

  200. What is the self-referencing constraint?
    Answer:
    • The self-referencing constraint limits in a single table the changes to a primary key that the related foreign key defines The foreign key in a self referencing table must specify the DELETE CASCADE rule .

  201. What are delete-connected tables?
    Answer:
    • Tables related with a foreign key are called delete-connected because a deletion in the primary key table can affect the contents of the foreign key table .

  202. When can an insert of a new primary key value threaten referential integrity?
    Answer:
    • Never New primary key values are not a problem However, the values of foreign key inserts must have corresponding primary key values in their related tables And updates of primary key values may require changes in foreign key values to maintain referential integrity.

  203. In terms of DB2 indexing, what is the root page?
    Answer:
    • The simplest DB2 index is the B-tree and the B-tree's top page is called the root page The root page entries represent the upper range limits of the index and are referenced first in a search.

  204. How does Db2 use multiple table indexes?
    Answer:
    • DB2 use the multiple indexes to satisfy multiple predicates in a SELECT statement that are joined by an AND or OR.

  205. What are some characteristics of columns that benefit from indexes?
    Answer:
    • Primary key and foreign key columns; columns that have uniue values; columns that have aggregates computed frequently and columns used to test the existence of a value.

  206. What is a composite index and how does it differ from a multiple index?
    Answer:
    • A multiple index is not one index but two indexes for two different columns of a table A composite index is one index made up of combined values from two columns in a table If two columns in a table will often be accessed together a composite index will be efficient.

  207. What is meant by index cardinality?
    Answer:
    • The number of distinct values for a column is called index cardinality DB2's RUNSTATS utility analyzes column value redundancy to determine whether to use a tablespace or index scan to search for data .

  208. What is a clustered index?
    Answer:
    • For a clustered index DB2 maintains rows in the same seuence as the columns in the index for as long as there is free space DB2 can then process that table in that order efficiently.

  209. What keyword does an SQL SELECT statement use for a string search?
    Answer:
    • The LIKE keyword allows for string searches The % sign is used as wildcard.

  210. What are some SQL aggregates and other built-in functions?
    Answer:
    • The common aggregate, built-in functions are AVG, SUM, MIN, MAX,COUNT and DISTINCT.

  211. How is the SUBSTR keyword used in SQL?
    Answer:
    • SUBSTR is used for string manipulation with column name, first position and string length used as arguments. Eg. SUBSTR (NAME, 1 3) refers to the first three characters in the column NAME.

  212. What are the three DB2 date and time data types and their associated functions?
    Answer:
    • The three data types are DATE, TIME and TIMESTAMP CHAR can be used to specify the format of each type The DAYS function calculates the number of days between two dates (It's Y2K compliant).

  213. Explain transactions, commits and rollbacks in DB2.
    Answer:
    • In DB2 a transaction typically requires a series of updates, insertions and deletions that represent a logical unit of work A transaction puts an implicit lock on the DB2 data Programmers can use the COMMIT WORK statement to terminate the transaction creating smaller units for recovery If the transaction fails DB2 uses the log to roll back values to the start of the transaction or to the preceding commit point.

  214. What are the four lockable units for DB2?
    Answer:
    • DB2 imposes locks of four differing sizes: pages, tables, table space and for indexes sub page.

  215. What are the three lock types?
    Answer:
    • The three types are shared, update and exclusive Shared locks allow two or more programs to read simultaneously but not change the locked space An exclusive lock bars all other users from accessing the space An update lock is less restrictive; it allows other transactions to read or acquire shared locks on the space.

  216. What is isolation level?
    Answer:
    • SQL statements may return any number of rows, but most host languages deal with one row at a time by declaring a cursor that presents each row at a unique isolation level.



Volta a página anterior

Volta ao Menu Principal