DB2
DB2
1) What RDMS objects are created with the SQL CREATE statements?
A) The SQL CREATE statements are used to create the following objects:
STOGROUP A storage group
DATABASE A logical collection of tables
TABLESPACE An area that stores tables
TABLE A data structure organized by a specified columns
INDEX An alternate path to a table data
VIEW An alternate representation of one or more tables
SYNONYM An alternate name for local table or view
ALIAS An alternate name for a table definition which may be local or remote, existence
or nonexistent
2) What RDMS objects are required before you can create a table?
A) Before you can create a table, you need an existing database and tablespace.
8) Which RDMS objects can you change with the SQL ALTER statements?
A) The SQL ALTER statement can change a table index, a table, a tablespace, or a
STOGROUP.
24) What techniques are used to retrieve data from more than one table in a
single SQL statement?
A) Joins, unions and nested selects are used to retrieve data.
29) What keyword does an SQL SELECT statement use for a string search?
A) The LIKE keyword allows for string searches. The % sign is used as a wildcard.
30) What are some SQL aggregates and other built-in functions?
A) The common aggregate, built-in functions are AVG, SUM, MIN, MAX, COUNT and
DISTINCT.
31) How is the SUBSTR keyword used in SQL?
A) SUBSTR is used for string manipulation with column name, first position and string
length used as arguments. E.g.
SUBSTR (NAME, 1 3) refers to the first three characters in the column NAME.
34) What is a NULL value? What are the pros and cons of using NULLS?
A) 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.
37) When can an insert of a new primary key value threaten referential
integrity?
A) 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.
44) Any SQL implementation covers data types in couple of main categories.
Which of the following are those data
types ? (Check all that apply)
A). NUMERIC
B). CHARACTER
C). DATE AND TIME
D). BLOBS E. BIT
A) A,B,C. Not all SQL implementations have a BLOB or a BIT data types.
45) We have a table with a CHARACTER data type field. We apply a ">" row
comparison between this field and
another CHARACTER field in another table. What will be the results for records
with field value of NULL?
(Check one that applies the best)
A. TRUE
B. B. FALSE
C. C. UNKNOWN
D. D. Error.
E. E. Those records will be ignored
A) C. NULL in a row when compared will give an UNKNOWN result.
46) Any database needs to go through a normalization process to make sure
that data is represented only once. This
will eliminate problems with creating or destroying data in the database. The
normalization process is done
usually in three steps which results in first, second and third normal forms.
Which best describes the process to
obtain the third normal form? (Check one that applies the best)
A. Each table should have related columns.
B. Each separate table should have a primary key.
C. We have a table with multi-valued key. All columns that are dependent
on only one or on some of the keys should be moved in a different table.
D. If a table has columns not dependent on the primary keys, they need to
be moved in a separate table.
E. E. Primary key is always UNIQUE and NOT NULL.
A) D. All columns in a table should be dependent on the primary key. This will eliminate
transitive dependencies in
which A depends on B, and B depends on C, but we're not sure how C depends on A.
48) What are common SQL abend codes? (e.g. : 0,100 etc.,)
A) -818 time stamp mismatch
-180 wrong data moved into date field
65) How would you find out the total number of rows in a table?
A) Use SELECT COUNT(*) ...
72) How do you retrieve the first 5 characters of FIRSTNAME column of EMP
table?
A) SELECT SUBSTR(FIRSTNAME,1,5) FROM EMP;
73) How do you concatenate the FIRSTNAME and LASTNAME from EMP table to
give a complete name?
A) SELECT FIRSTNAME || ' ' || LASTNAME FROM EMP;
80) What is 'LIKE' used for in WHERE clause? What are the wildcard
characters?
A) LIKE is used for partial string matches. '%' ( for a string of any character ) and '_' (for
any single character ) are the
two wild card characters.
81) When do you use a LIKE statement?
A) To do partial search e.g. to search employee by name, you need not specify the
complete name; using LIKE, you can
search for partial string matches.
84) Consider the employee table with column PROJECT nullable. How can you
get a list of employees who are not
assigned to any project?
A) SELECT EMPNO FROM EMP WHERE PROJECT IS NULL;
89) How would you retrieve rows from a DB2 table in embedded SQL?
A)Either by using the single row SELECT statements,or by using the CURSOR.
90) Apart from cursor, what other ways are available to you to retrieve a row
from a table in embedded SQL?
A)Single row SELECTs.
91) How do you specify and use a cursor in a COBOL program?
A)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.
94) Can you have more than one cursor open at any one time in a program ?
A)Yes.
107) On the create tablespace, what does the CLOSE parameter do?
A) CLOSE physically closes the tablespace when no one is working on the object. DB2
(release 2.3) will logically close tablespaces.
130) How would you move a tablespace (using STOGROUP) to a different DASD
volume allocated to that tablespace?
A) If the tablespace used is only allocated to that STOGROUP:
- ALTER STOGROUP - add volume (new) delete volume(old)
- REORG TABLESPACE or RECOVER TABLESPACE
Create a new STOGROUP that points to the new volume. ALTER the tablespace and
REORG or RECOVER the
tablespace.
133) Can DASD types assigned to storage groups be intermixed(i.e., 3350s and
3380s)?
A) No
134) What are the three types of page locks that can be held?
A) Exclusive, update, and share.
135) Can DB2 be accessed by TSO users? If yes, which command is used to
invoke DB2?
A) DB2 can be invoked by TSO users by using the DSN RUN command.
136) How are write I/Os from the buffer pool executed?
A) Asynchronously.
138) In which column of which DB2 catalog would you find the length of the
rows for all tables?
A) In the RECLENGTH column of SYSIBM.SYSTABLES
142) Where would you find information about the type of database authority
held by the user?
A) SYSIBM.SYSDBAUTH.
143) Where could you look if you had a question about whether a column has
been defined as an index?
A) This information can be found in SYSIBM.SYSINDEXES.
144) Once you create a view, where would information about the view be
stored?
A) When a view is created, system information about the view is stored in
SYSIBM.SYSVIEWS.
145) What is the SQL Communications Area and what are some of its key
fields?
A) 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.
147) How do you leave the cursor open after issuing a COMMIT? (for DB2 2.3 or
above only)
A) Use WITH HOLD option in DECLARE CURSOR statement. But, it has not effect in
psuedo-conversational CICS programs.
149) What is the physical storage length of each of the following DB2 data
types: DATE, TIME, TIMESTAMP?
A54) DATE: 4bytes
TIME: 3bytes
TIMESTAMP: 10bytes
150) What is the COBOL picture clause of the following DB2 data types: DATE,
TIME, TIMESTAMP?
A) DATE: PIC X(10)
TIME : PIC X(08)
TIMESTAMP: PIC X(26)
151) What is the COBOL picture clause for a DB2 column defined as
DECIMAL(11,2)? - GS
A) PIC S9(9)V99 COMP-3.
Note: In DECIMAL(11,2), 11 indicates the size of the data type and 2 indicates the
precision.
154) Is it mandatory to use DCLGEN? If not, why would you use it at all?
A) 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.
158) Assuming that a site's standard is that pgm name = plan name, what is
the easiest way to find out which
programs are affected by change in a table's structure?
A) Query the catalogue tables SYSPLANDEP and SYSPACKDEP.
160) How can you quickly find out the number of rows updated after an update
statement?
A) Check the value stored in SQLERRD(3).
170) I use CS and update a page. Will the lock be released after I am done with
that page?
A) No.
180) What else is there in the PLAN apart from the access path?
A) PLAN has the executable code for the SQL statements in the host program
181) What happens to the PLAN if index used by it is dropped?
A) Plan is marked as invalid. The next time the plan is accessed, it is rebound.
186) In SPUFI suppose you want to select maximum of 1000 rows, but the
select returns only 200 rows. What are the 2 SQLCODEs that are returned?
A) +100 (for successful completion of the query), 0 (for successful COMMIT if
AUTOCOMMIT is set to Yes).
187) How would you print the output of an SQL statement from SPUFI?
A) Print the output dataset.
188) Lot of updates have been done on a table due to which indexes have
gone haywire. What do you do?
A) Looks like index page split has occurred. DO a REORG of the indexes.
189) What is dynamic SQL?
A) Dynamic SQL is a SQL statement created at program execution time.
191) 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?
A) There may be one of the following reasons:
Probably RUN STATS is not done and the program is using a wrong index due to incorrect
stats.
Probably RUNSTATS is done and optimizer has chosen a wrong access path based on the
latest statistics.
195) What does it mean if the null indicator has -1, 0, -2?
A) -1 : the field is null; 0 : the field is not null; -2 : the field value is truncated
197) If I have a view which is a join of two or more tables, can this view be
updatable?
A) No.
212) What is the difference between primary key & unique index ?
A) Primary Key: a relational database constraint. Primary key consists of one or more
columns that uniquely identify a row in the table. For a normalized relation, there is one
designated primary key.
Unique index: a physical object that stores only unique values. There can be one or more
unique indexes on a table.
213) What is sqlcode -922 ?
A) Authorization failure
221) What do you mean by NOT NULL WITH DEFAULT? When will you use it?
A) This column cannot have nulls and while insertion, if no value is supplied then it will
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.
222) What do you mean by NOT NULL? When will you use it?
A) The column cannot have nulls. Use it for key fields.
231) When is the authorization check on DB2 objects done - at BIND time or
run time?
A) At run time.
234) I need to view the number of tables existing under one particular Owner.
Is it possible? If so, pl give the SQL query for this?
A) The query SELECT * FROM SYSIBM.SYSTABLES WHERE CREATOR = 'owner id' This
displays the table names with that If you want only the number of tables give the
following query. SELECT COUNT(*) FROM SYSIBM.SYSTABLES WHERE CREATOR = 'owner
id' Make sure that you are in correct subsystem.
235) I need to view the number of tables existing under one particular Owner.
Is it possible? If so, pl give the SQL query for this?
A) The query SELECT * FROM SYSTABLES WHERE OWNER= should work.
236) I need to view the number of tables existing under one particular Owner.
Is it possible? If so, pl give the SQL query for this?
A) Db2 records information for its operation in a catalog which is actually a group of
tables. So we can use the SYSTABLES to get answer to ur query.
238) can I alter a table (e.g. adding a column) when other user is selecting
some columns or updating some columns from the same table?
A) yes possible. until the updation 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.
240) 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 B. A thread between TSO & DB2 is established while attempting to make
connection between tso & db2.
241) How many buffer pools are available in db2?
A) Ten 32k size buffer pools and fifty 4k size buffer pools (bp0 to bp49)default buffer
pools are bp0,bp1,bp2 & bp32
243) How many Buffer pools are there in DB2 and what are they?
A) There are 4 Buffer pools. They are BP0,BP1,BP2 and BP32.
246) How do you filter out the rows retrieved from a Db2 table ?
A) one way is to use The SQL WHERE clause.
253) 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.
259) Can All Users Have The Privilege To Use The SQL Statement Select *
(DML)?
A) No the user should be granted privilege to use it.
261) what's the best lock size 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 R/W. If you use lock size =any, Db2 would automatically determine
what type of locks it should use.
262) what's the error code for Unique Index Violation?
A) -803
263) Can you define an Index if the table size less than 10 PAGES?
A) NO
264) What's the Maximum Length of SQLCA and what's the content of
SQLCABC?
A) The Max length is 136. and the SQLCABC has the Value of SQLCA.
266) What's the maximum number of characters that a tablename can have?
A) The answer is 18 characters.
268) when does the SQL statement gets executed when you use cursor in the
application programming ?
A) SQL statement gets executed when we open cursor
270) What is the difference between TYPE 1 index & TYPE 2 index
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.
271) What are the levels of isolation available with DB2V4
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 & data
concurrency is CS.
272) How do u achieve record level locking in DB2 versions when record level
locking is not allowed?
A) By having the length of the record greater than that of a page!
274) What does DML stand for and what are some examples of it?
A) Data Manipulation Language. Some examples are SELECT, INSERT, DELETE, REPLACE.
275) How to define the data items to receive the fetch items for the SQL?
A) Using the DSECT, followed by lines of - 'data items DS datatype'.
279) How do you declare a host variable (in COBOL) for an attribute named
emp-name of type VARCHAR(25) ?
A) 01 EMP-GRP. 49 E-LEN PIC S9(4) COMP. 49 E-NAME PIC X(25).
282) what are the max. & min. no. of partitions allowed in a partition
tablespace?
A) minimum is 4. maximum is 64.
284) 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
289) What is normalization and what are the five normal forms?
A) 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.
290) What are foreign keys?
A) These are attributes of one table that have matching values in a primary key in
another table, allowing for relationships between tables.
293) What techniques are used to retrieve data from more than one table in a
single SQL statement?
A) Joins, unions and nested selects are used to retrieve data.
294) What do the initials DDL and DML stand for and what is their meaning?
A) 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.
308) What is the significance of DB2 free space and what parameters control
it?
A) 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.
309) What is a NULL value? What are the pros and cons of using NULLS?
A) 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.
313) If the base table underlying a view is restructured, eg. attributes are
added, does the application code accessing the view need to be redone?
A) 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.
314) Under what circumstances will DB2 allow an SQL statement to update
more than one primary key value at a time?
A) Never. Such processing could produce duplicate values violating entity integrity.
Primary keys must be updated one at a time.
315) What is the cascade rule and how does it relate to deletions made with a
subselect?
A) The cascade rule will not allow deletions based on a subselect that references the
same table from which the deletions are being made.
316) What is the self-referencing constraint?
A) 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.
318) When can an insert of a new primary key value threaten referential
integrity?
A) 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.
321) What are some characteristics of columns that benefit from indexes?
A) 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.
322) What is a composite index and how does it differ from a multiple index?
A) 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.
325) What keyword does an SQL SELECT statement use for a string search?
A) The LIKE keyword allows for string searches. The % sign is used as a wildcard.
326) What are some SQL aggregates and other built-in functions?
A) The common aggregate, built-in functions are AVG, SUM, MIN, MAX, COUNT and
DISTINCT.
328) What are the three DB2 date and time data types and their associated
functions?
A) 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).
337) What is the significance of the CURSOR WITH HOLD clause in a cursor
declaration?
A) The clause avoids closing the cursor and repositioning it to the last row processed
when the cursor is reopened.
338) What is the SQL Communications Area and what are some of its key
fields?
A) 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.
341) DB2 can implement a join in three ways using a merge join, a nested join
or a hybrid join. Explain the differences?
A) 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.
345) DB2 What is the difference between a package and a plan? 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?
A) 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 database 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.
Q246) What is an asychronous write?
A246) It is a write to disk that may occur before or long after a commit. The write is
controlled by the buffer manager.