ITJOBSHUB DB2 Interview Questions
ITJOBSHUB DB2 Interview Questions
A: The ability to join rows and combine data from two or more tables is one of
the most powerful features of relational system. There are three type of
joins:1. Equi-join; 2.Non-equijoin; 3.self-join
Q: Which is the most widely used batch performance monitor for DB2?
A: DB2PM
Q: Can I alter a table (like adding a column) when other user is selecting
some columns or updating some columns from the same table? A: 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.
Q: What are the different methods of accessing DB2 from TSO? How is the
connection established between TSO & DB2? A: 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.
A: Ten 32K size bufferpools and fifty 4K size buffer pools (BP0 to BP49).
Default buffer pools are BP0, BP1, BP2 & BP32
A: 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.
A: DSN RUN
Q: What is a collection?
Q: What is the equivalent Cobol Data type for Decimal (x,y) in DB2? What
does the current SQLID register contain?
A: 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.
A: DSNDB06
Q: When can you be sure that a query will return only one row?
A: When you use the primary key and only the primary key in the WHERE
clause.
A: 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.
A: 127
Q: Can all users have the privilege to use the SQL statement SELECT * (DML)?
A: 4K to 8K
Q: What's the best locksize that you could use when you create a tablespace?
A: The answer is LOCKSIZE = ANY. Unless you are sure what's the Purpose of
tablespace ie.,Read-only or Read/Write. If you use LOCKSIZE = ANY, DB2
would automatically determine what type of locks it should use.
Q: Can you define an Index if the table size is less than 10 PAGES?
A: NO
A: The maximum length is 136 and the SQLCABC has the Value of SQLCA.
A: Program name not in plan. Bind the plan and include the DBRM for the
program named as part of the plan.
Q: When does the SQL statement gets executed when you use cursor in the
application programming?
A: 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 retrieved faster as only the data pages are locked and not the index
pages. Hence TYPE 2 index is recommended.
A: CS RR UR (added new for DB2V4 which stands for uncommitted 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 and data concurrency is CS.
Q: How do you achieve record locking in DB2 in the versions which do not
support record level locking?
A: By having the record length more than half of the page size
Q: What does DML stand for and what are some examples of it?
A: Using QMF.
A: ONE
A: Fifteen
Q: What technique is used to retrieve data from more than one table in a
single SQL statement?
A: The JOIN statement combines data from more that two tables
A: 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.
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.
Answer: 127
Question: CAN ALL USERS HAVE THE PRIVILAGE TO USE THE SQL STATEMENT
SELECT * (DML)?
Answer: 4K to 8K
Question: what's the best locksize that you could use when you create a
tablespace?
Answer: The answer is Locksize = ANY.Unless you are Sure what's 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.
Answer: -803
Answer: ZERO
Question: Can you define an Index if the table size less than 10 PAGES?
Question: What's the Maximum Length of SQLCA and what's the content of
SQLCABC?
Answer: The Max length is 136. and the SQLCABC has the Value of SQLCA.
Question: Can you define an Index if the table size less than 10 PAGES?
Answer: The answer is 133. Usually it will be difficult monitor more than 3 or
4 volumes to a Stogroup.
Answer: Program name not in plan. Bind the plan and include the DBRM for
the program named as part of the plan.
Question: when does the sql statement gets executed when you use cursor in
the application programming ?
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).
Question: What is the difference 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. Hence TYPE 2 index is recommended.
Question: What are the levels of isolation available with DB2V4
Answer: CS RR UR( added new for DB2V4 which stands for uncommited read
which allows to retreive 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.
Question: How do you achieve record locking in DB2 in the versions which do
not support record level locking?
Answer: Y'day I had posted this que. The answer shud hv read as follows: By
having the record length more than half of the page size ! Sorry again &
Thanx
Question: How do u 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!
Question: How to define the dataitems to receive the fetch items for the SQL?
Question: How do you declare a host variable (in COBOL) for an attribute
named EMP-NAME of type VARCHAR(25) ?
Question: what are the max. & min. no. of partitions allowed in a partition
tablespace?
Answer: fifteen
Question: 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
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.
DB2
How would you find out the total number of rows in a table?
YES
Because SALARY is not declared to have NULLs and the employees for whom
the salary is not known are also counted
9. How do you concatenate the FIRSTNAME and LASTNAME from EMP table to
give a complete name?
Avoid -ve SQL CODE by handling nulls and zeroes in computations Substitute
a numeric value for any nulls used in computation
UNION : eliminates duplicates UNION ALL: retains duplicates Both these are
used to combine the results of different SELECT statements
Once
It has to be in a CURSOR
16. What is 'LIKE' used for in WHERE clause?What are the wildcard
characters?
LIKE is used for partial string matches '%' ( for a string of any character ) and
'_' (for any single character ) are the two wild card characters
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
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
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.
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
23. How would you retrieve rows from a DB2 table in embedded SQL?
Either by using the single row SELECT statements, or by using the CURSOR
24. Apart from cursor, what other ways are available to you to retrieve a row
from a table in embedded SQL?
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
No
28. Can you have more than one cursor open at any one time in a program?
Yes
Yes
30. How do you leave the cursor open after issuing a COMMIT?
Use WITH HOLD option in DECLARE CURSOR statement But, it has not effect
in psuedo-conversational CICS programs
32. What is the physical storage length of each of the following DB2 data
types:
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)
33. What is the COBOL picture clause for a DB2 column defined as
DECIMAL(11,2)?
Declaration Generator: used to create the host language copy books for the
table definitions Also creates the DECLARE table
EXEC SQL DECLARE TABLE statement which gives the layout of the table/view
in terms of DB2 datatypes. A host language copy book that gives the host
variable definitions for the column Names.
36. Is it mandatory to use DCLGEN? If not, why would you use it at all?
It is not mandatory to use DCLGEN Using DCLGEN, helps detect wrongly spelt
column names etc during the pre- compile stage itself ( because of the
DECLARE TABLE ) DCLGEN being a tool, would generate accurate host
variable definitions for the table reducing chances of error.
No Because the pre-compiler does not refer to the DB2 catalogue tables
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
40. 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 ?
Query the catalogue tables SYSPLANDEP and SYSPACKDEP
42. How can you Quickly find out the # of rows updated after an update
statement?
In userid PLAN_TABLE
CS: Releases the lock on a page after use RR: Retains all locks acquired till
end of transaction
51. Where do you specify them ?
53. I use CS and update a page Will the lock be released after I am done with
that page?
No
Determine the point at which DB2 acquires or releases locks against table
and Tables spaces, including intent locks.
63. What else is there in the PLAN apart from the access path?
PLAN has the executable code for the SQL statements in the host program
Plan is marked as invalid The next time the plan is accessed, it is rebound
They contain executable code for SQL statements for one DBRM
1. Avoid having to bind a large number of DBRM members into a plan 2. Avoid
cost of a large bind Avoid the entire transaction being unavailable during bind
and automatic rebind of a plan. 4. Minimize fallback complexities if changes
result in an error
A user defined name that is the anchor for packages It has not physical
existence Main usage is to group packages
68. In SPUFI suppose you want to select max of 1000 rows , but the select
returns only 200 rows What are the 2 Sql codes that are returned?
69. How would you print the output of an SQL statement from SPUFI?
Lot of updates have been done on a table due to which indexes have gone
haywire What do you do?
Looks like index page split has occured DO a REORG of the indexes
73. Suppose I have a program which uses a dynamic SQL and it has been
performing well till now Off late, I find that the performance has deteriorated
What happened?
Probably RUN STATS is not done and the program is using a wrong index due
to incorrect status Probably RUNSTATS is done and optimizer has chosen a
wrong access path based on the latest statistics
As an extra-byte prefix to the column value physically, the null prefix is Hex
'00' if the value is present and Hex 'FF' if it is not.
S9(4) COMP
77. What does it mean if the null indicator has -1, 0, -2?
-1 : the field is null 0 : the field is not null -2 : the field value is truncated
To insert a NULL, move -1 to the null indicator To insert a valid value, move 0
to the null indicator
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
When is it used?
When a table is Loaded with ENFORCE NO option, then the table is left in
CHECK PENDING status It means that the LOAD utility did not perform
constraint checking
A QUIESCE flushes all DB2 buffers on to the disk This gives a correct snapshot
of the database and should be used before and after any IMAGECOPY to
maintain consistency
Causes the data rows to be stored in the order specified in the index A
mandatory index defined on a partitioned table space
89. How many clustering indexes can be defined for a table?
: ONLY ONE
90. What is the difference between Primary Key & Unique index ?
Authorization failure
This is generated when the consistency tokens in the DBRM and the load
module are different
Not all of them Some views are updatable eg single table view with all the
fields or mandatory fields Examples of non-updatable views are views which
are joins, views that contain aggregate functions(such as MIN), and views
that have GROUP BY clause
95. If I have a view which is a join of two or more tables, can this view be
updatable?
NO
Inner Join: combine information from two or more tables by comparing all
values that meet the search criteria in hte designated column or columns of
one table with all the class in corresponding columns of the other table or
tables This kind of join which involve a match in both columns are called
inner joins. Outer join is one in which you want both matching and non
matching rows to be returned DB2 has no specific operator for outer joins, it
can be simulated by combining a join and a correlated sub query with a
UNION.
Simple Table space Can contain one or more tables Rows from multiple tables
can be interleaved on a page under the DBAs control and maintenance
Segmented Table space Can contain one or more tables Table space is divided
into segments of 4 to 64 pages in increments of 4 pages Each segment is
dedicated to single table A table can occupy multiple segments Partitioned
Table space Can contain one table Tables pace is divided into parts and each
part is put in a separate VSAM Data Set
Synonym is an alternate name for a table or view used mainly to hide the
leading Qualifier of a table or view A synonym is accessible only by the
creator
104. What do you mean by NOT NULL WITH DEFAULT? When will you use it?
This column cannot have nulls and while insertion, if no value is supplied then
it wil have zeroes, spaces or date/time depending on whether it is numeric,
character or date/time Use it when you do not want to have nulls but at the
same time cannot give values all the time you insert this row
105. What do you mean by NOT NULL?When will you use it?
The column cannot have nulls Use it for key fields
When a column which contains long text, eg remarks, notes, may have in
most cases less than 50% of the maximum length
1. Can lead to high space utilization if most of the values are close to
MAXIMUM. 2. Positioning of VARCHAR column has to be done carefully as it
has performance implications. 3. Relocation of rows to different pages can
lead to more I/Os on retrieval.
First CREATE MANAGER table with EMP# as the primary key Then ALTER it to
define the foreign key.
109. When is the authorization check on DB2 objects done. BIND or run time?
At run TIME
Recording SQL statements that access a table Specified at table creation time
or through alter
An access path is the method used to access data specified in DB2 SQL
Statements.
114. What is normalization and what are the five normal forms?
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.
These are attributes of one table that have matching values in a primary key
in another table, allowing for relationships between tables.
118. What techniques are used to retrieve data from more than one table in a
single SQL Statements?
119. What do the initials DDL and DML stand for and what is their meaning?
DDL is data definition language and DML is data manipulation language DDL
statements are CREATE, ALTER, TRUNCATE DML statements are SELECT,
INSERT, DELETE and UPDATE .
A view is a virtual table made up of data from base tables and other views,
but not stored separately.
An outer join includes rows from tables when there are no matching values in
the Tables.
Sub select is a select which works in conjunction with another select A nested
select is a kind of Sub Select where the inner select passes to the where
criteria for the outer select.
Tables are stored in Table Space (hence the name)! There are three types of
Table Space simple, segmented and partitioned
128. Usually, which is more important for DB2 system performance - CPU
processing or I/O access?
I/O operations are usually most critical for DB2 performance (or any other
database for that matter)
The database descriptor, DBD is the DB2 component that limits access to the
database whenever objects are created, altered or dropped.
To maintain the integrity of DB2 objects the DBD permits access to only on
object at a time Lock contention happens if several objects are required by
contending application processes simultaneously.
133. What is the significance of DB2 free space and what parameters control
it?
The two parameters used in the CREATE statement are the PCTFREE which
specifies the percentage of free space for each page and FREEPAGE which
indicates the number of pages to be loaded with data between each free
page Free space allows room for the insertion of new rows
134. What is a NULL value? What are the pros and cons of using NULLS?
A NULL value takes up one byte of storage and indicates that a value is not
present as opposed to a space or zero value It's the DB2 equivalent of TBD on
an organizational chart and often correctly portrays a business situation
Unfortunately, it requires extra coding for an application program to handle
this situation.
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.
143. When can an insert of a new primary key value threaten referential
integrity?
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.
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.
146. What are some characteristics of columns that benefit from indexes?
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.
147. What is a composite index and how does it differ from a multiple index?
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.
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 .
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.
150. What keyword does an SQL SELECT statement use for a string search?
The LIKE keyword allows for string searches The % sign is used as wildcard.
151. What are some SQL aggregates and other built-in functions?
The common aggregate, built-in functions are AVG, SUM, MIN, MAX,COUNT
and DISTINCT.
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.
153. What are the three DB2 date and time data types and their associated
functions?
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).
DB2 imposes locks of four differing sizes: pages, tables, table space and for
indexes sub page.
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.
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.
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.
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.
162. What is the significance of the CURSOR WITH HOLD clause in a cursor
declaration?
The clause avoids closing the cursor and repositioning it to the last row
processed when the cursor is reopened.
163. What is the SQL Communications Area and what are some of its key
fields?
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.
The FREE command can be used to delete plans and/or packages no longer
Needed.
168. DB2 can implement a join in three ways using a merge join, a nested
join or a hybrid join Explain the differences.
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.
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.
170. What is the difference between IN sub selects and EXISTS sub select?
A Cartesian product results from a faulty query It is a row in the results for
every combination in the join tables.
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.
It is a write to disk that may occur before or long after a commit The write is
controlled by the buffer manager.
A lock is the mechanism that controls access to data pages and table spaces.
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.
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.
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.
A thread is the connection between DB2 and some other subsystem, such as
CICS or IMS/DC.
What is Bind ? What are the different bind parameters ?
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.
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) .
Only one.
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.
What is a filter factor? 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.
What is RUNSTATS? When will you do this? After RUNSTATS what will you do?
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.
What is a cursor?
Cursor is 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. A cursor is a named control structure
used to make multiple number of rows available to a program and then to
process the selected table data one row at a time (similar to reading a
sequential file)
Working storage.
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.
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.
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 techniques are used to retrieve data from more than one table in a
single SQL statement?
An outer join includes rows from tables when there are no matching values in
the tables.
204.What is tablespace?
Tables are stored in tablespaces (hence the name)! There are three types of
tablespaces: simple, segmented and partitioned.
I/O operations are usually most critical for DB2 performance (or any other
database for that matter).
To maintain the integrity of DB2 objects the DBD permits access to only on
object at a time. Lock contention happens if several objects are required by
contending application processes simultaneously.
210.What is SPUFI?
SPUFI stands for SQL processing using file input. It is the DB2 interactive
menu-driven tool used by developers to create database objects.
211.What is the significance of DB2 free space and what parameters control
it?
The two parameters used in the CREATE statement are the PCTFREE which
specifies the percentage of free space for each page and FREEPAGE which
indicates the number of pages to be loaded with data between each free
page.Free space allows room for the insertion of new rows.
212.What is a NULL value?What are the pros and cons of using NULLS?
A NULL value takes up one byte of storage and indicates that a value is not
present as opposed to a space or zero value. It's the DB2 equivalent of TBD
on an organizational chart and often correctly portrays a business situation.
Unfortunately, it requires extra coding for an application program to handle
this situation.
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.
218.What is the cascade rule and how does it relate to deletions made with a
subselect.
The cascade rule will not allow deletions based on a subselect that references
the same table from which the deletions are being made.
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.
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.
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.
225.What is a composite index and how does it differ from a multiple index?
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.
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.
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.
228.What keyword does an SQL SELECT statement use for a string search?
The LIKE keyword allows for string searches. The % sign is used as a wildcard.
The common aggregate, built-in functions are AVG, SUM, MIN, MAX, COUNT
and DISTINCT.
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.
231.What are the three DB2 date and time data types and their associated
functions?
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).
233.What is deadlock?
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.
DB2 imposes locks of four differing sizes: pages, tables, tablespace and for
indexes subpage.
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.
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.
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.
240.What is the significance of the CURSOR WITH HOLD clause in a cursor
declaration?
The clause avoids closing the cursor and repositioning it to the last row
processed when the cursor is reopened.
241.What is the SQL Communications Area and what are some of its key
fields?
243.What is DCLGEN?
The FREE command can be used to delete plans and/or packages no longer
needed.
245.DB2 can implement a join in three ways using a merge join, a nested join
or a hybrid join. Explain the differences.
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.
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.
It is a write to disk that may occur before or long after a commit. The write is
controlled by the buffer manager.
249.What is a lock?
A lock is the mechanism that controls access to data pages and tablespaces.
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.