IBM DB2 Job Interview Questions and Solutions

9/14/2009 No Comment

DB2 Job Interview Questions and Solutions.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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).

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.

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.

What are the four lockable units for DB2?

Answer : DB2 imposes locks of four differing sizes: pages, tables, tablespace and for indexes subpage.

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.

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.

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.

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.

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.

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.

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.

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.

What is the FREE command?

Answer : The FREE command can be used to delete plans and/or packages no longer needed.

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.

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.

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).

What is an asynchronous 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.

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

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.
Related Posts


No comments :

 

Aired | The content is copyrighted and may not be reproduced on other websites. | Copyright © 2009-2016 | All Rights Reserved 2016

Contact Us | About Us | Privacy Policy and Disclaimer