50 DB2 Interview Questions and Answers

10/01/2009 No Comment

50 Commonly Asked Interview Questions and Answers in DB2.

The Questions are collected from various Interview Sources.

1. What is lock escalation?
Answer : Promoting a PAGE lock-size to table or tablespace lock-size when a transaction has acquired more locks than specified in NUMLKTS. Locks should be taken on objects in single tablespace for escalation to occur.

2. What are the various locks available?
Answer : SHARE, EXCLUSIVE, UPDATE

3. Can I use LOCK TABLE on a view?
Answer : No. To lock a view, take lock on the underlying tables.

4. What is ALTER? 

Answer : SQL command used to change the definition of DB2 objects.

5. What is a DBRM, PLAN?

Answer : DBRM: DataBase Request Module, has the SQL statements extracted from the host language program by the pre-compiler.

PLAN: A result of the BIND process. It has the executable code for the SQL statements in the DBRM.

6. What is ACQUIRE/RELEASE in BIND?

Answer : Determine the point at which DB2 acquires or releases locks against table and tablespaces, including intent locks.

7. What else is there in the PLAN apart from the access path?

Answer : PLAN has the executable code for the SQL statements in the host program

8. What happens to the PLAN if index used by it is dropped?

Answer : Plan is marked as invalid. The next time the plan is accessed, it is rebound.

9. What are PACKAGES?

Answer : They contain executable code for SQL statements for one DBRM.

10. What are the advantages of using a PACKAGE?

Answer : 1. Avoid having to bind a large number of DBRM members into a plan
2. Avoid cost of a large bind
3. Avoid the entire transaction being unavailable during bind and automatic rebind of a plan
4. Minimize fallback complexities if changes result in an error.

11. What is a collection?

Answer : Collection a user defined name that is the anchor for packages. It has not physical existence. Main usage is to group packages.In SPUFI suppose you want to select max. of 1000 rows , but the select returns only 200 rows.

12. What are the 2 sqlcodes that are returned?

Answer : 100 ( for successful completion of the query ), 0 (for successful COMMIT if AUTOCOMMIT is set to Yes).

13. How would you print the output of an SQL statement from SPUFI?

Answer : Print the output dataset.

14. Lot of updates have been done on a table due to which indexes have gone haywire. What do you do?

Answer : Looks like index page split has occurred. DO a REORG of the indexes.

15. What is dynamic SQL?

Answer : Dynamic SQL is a SQL statement created at program execution time.

16. When is the access path determined for dynamic SQL?

Answer : At run time, when the PREPARE statement is issued.

17. 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?

Answer : 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.

18. How does DB2 store NULL physically?
Answer : It acts 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.

19. How do you retrieve the data from a nullable column?

Answer : Use null indicators. Syntax ... INTO :HOSTVAR:NULLIND

20. What is the picture clause of the null indicator variable?

Answer : S9(4) COMP.

21. What does it mean if the null indicator has -1, 0, -2? Answer : 

1 : the field is null
0 : the field is not null
-2 : the field value is truncated

22. How do you insert a record with a null column?

Answer : To insert a NULL, move -1 to the null indicator
To insert a valid value, move 0 to the null indicator

23. What is RUNSTATS?

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.

24. When will you chose to run RUNSTATS?

Answer : After a load, or after mass updates, inserts, deletes, or after REORG.

25. Give some example of statistics collected during RUNSTATS?

Answer : # of rows in the table
Percent of rows in clustering sequence
# of distinct values of indexed column
# of rows moved to a nearby/far away page due to row length increase

26. What is REORG? When is it used?

Answer : REORG reorganizes data on physical storage to recluster rows, positioning overflowed rows in their proper sequence, to reclaim space, to restore free space. It is used after heavy updates, inserts and delete activity and after segments of a segmented tablespace have become fragmented.

27. What is IMAGECOPY? 

Answer : It is full backup of a DB2 table which can be used in recovery.

28. When do you use the IMAGECOPY?

Answer : To take routine backup of tables
After a LOAD with LOG NO
After REORG with LOG NO

29. What is COPY PENDING status?

Answer : A state in which, an image copy on a table needs to be taken, In this status, the table is available only for queries. You cannot update this table. To remove the COPY PENDING status, you take an image copy or use REPAIR utility.

30. What is CHECK PENDING?

Answer : 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.

31. What is QUIESCE?
Answer : 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.

32. What is a clustering index ?

Answer : Causes the data rows to be stored in the order specified in the index. A mandatory index defined on a partitioned table space.

33. How many clustering indexes can be defined for a table?

Answer : Only one.

34. What is the difference between primary key & unique index?

Answer : Primary : 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.

35. What is sqlcode -922?

Answer : Authorization failure

36. What is sqlcode -811?

Answer : SELECT statement has resulted in retrieval of more than one row.

37. What does the sqlcode of -818 pertain to?

Answer : This is generated when the consistency tokens in the DBRM and the load module are different.

38. Are views updateable?
Answer : Not all of them. Some views are updateable e.g. single table view with all the fields or mandatory fields. Examples of non-updateable views are views which are joins, views that contain aggregate functions (such as MIN), and views that have GROUP BY clause.

39. If I have a view which is a join of two or more tables, can this view be updateable? 

Answer : No.

40. What are the 4 environments which can access DB2?

Answer : TSO, CICS, IMS and BATCH

41. What is an inner join, and an outer join?

Answer : Inner Join: combine information from two or more tables by comparing all values that meet the search criteria in the designated column or columns of on e table with the entire clause 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.

42. What is FREEPAGE and PCTFREE in TABLESPACE creation?

Answer : PCTFREE: percentage of each page to be left free
FREEPAGE: Number of pages to be loaded with data between each free page

43. What are simple, segmented and partitioned table spaces ?

Answer : Simple Tablespace: Can contain one or more tables
Rows from multiple tables can be interleaved on a page under the DBAs control and maintenance

Segmented Tablespace:Can contain one or more tables
Tablespace 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 Tablespace:Can contain one table
Tablespace is divided into parts and each part is put in a separate VSAM dataset.

44. What is filter factor?

Answer : one divided by the number of distinct values of a column.

45. What is index cardinality? 

Answer : The number of distinct values a column or columns contain.

46. What is a synonym ?

Answer : 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.

47. What is the difference between SYNONYM and ALIAS?

Answer : SYNONYM: is dropped when the table or tablespace is dropped. Synonym is available only to the creator.ALIAS: is retained even if table or tablespace is dropped. ALIAS can be created even if the table does not exist. It is used mainly in distributed environment to hide the location info from programs. Alias is a global object & is available to all.

48. What do you mean by NOT NULL WITH DEFAULT? When will you use it?

Answer : 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.

49. What do you mean by NOT NULL? When will you use it?

Answer : The column cannot have nulls. Use it for key fields.

50. When would you prefer to use VARCHAR?

Answer : When a column which contains long text, e.g. remarks, notes, may have in most cases less than 50% of the maximum length.
108) What are the disadvantages of using VARCHAR?
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.

51. How do I create a table MANAGER ( EMP#, MANAGER) where MANAGER is a foreign key which references to EMP# in the same table? Give the exact DDL.

Answer : First CREATE MANAGER table with EMP# as the primary key. Then ALTER it to define the foreign key.

52. When is the authorization check on DB2 objects done - at BIND time or run time?
Answer : At run time.

53. What is auditing?
Answer : Recording SQL statements that access a table. Specified at table creation time or through alter.
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