DB2 is a subsystem of the MVS operating system. It is a Database Management System (DBMS) for that operating system.
The path that is used to get to data specified in SQL statements.
It is an alternate name that can be used in SQL statements to refer to a table or view in the same or remote DB2 subsystem.
Plan is a DB2 object (produced during the bind process) that associates one or more database request modules with a plan name.
Bind is a process that builds “access paths” to DB2 tables. A bind uses the Database Request Modules(s) (DBRM(s)) from the DB2 pre-compile step as input and produces an application plan. It also checks the user’s authority and validates the SQL statements in the DBRM(s).
The database request module produced during the pre-compile. The SYSIBM.SYSSTMT table of the DB2 catalog.
The attachment facility is an interface between DB2 and TSO, IMS/VS, CICS, or batch address spaces. It allows application programs to access DB2.
AUTO COMMIT is a SPUFI option that commits the effects of SQL statements automatically if they are successfully executed.
A base table is a real table - a table that physically exists in that there are physical stored records..
The buffer manager is the DB2 component responsible for physically transferring data between an external medium and (virtual) storage (performs the actual I/O operations). It minimizes the amount of physical I/O actually performed with sophisticated buffering techniques(i.e., read-ahead buffering and look-aside buffering).
A buffer pool is main storage that is reserved to satisfy the buffering requirements for one or more tablespaces or indexes, and is made up of either 4K or 32K pages.
CLOSE physically closes the tablespace when no one is working on the object. DB2 (release 2.3) will logically close tablespaces.
A DBRM is a DB2 component created by the DB2 pre-compiler containing the SQL source statements extracted from the application program. DBRMs are input to the bind process.
A data page is a unit of retrievable data, either 4K or 32K (depending on how the table is defined), containing user or catalog information.
They are attributes of columns, literals, and host variables. The data types are SMALLINT, INTEGER, FLOAT, DECIMAL, CHAR, VARCHAR, DATE and TIME.
COMMIT will allow data changes to be permanent. This then permits the data to be accessed by other units of work. When a COMMIT occurs, locks are freed so other applications can reference the just committed data.
Concurrency is what allows more than one DB2 application process to access the same data at essentially the same time. Problems may occur, such as lost updates, access to uncommitted data, and un-repeatable reads.
It is cursor stability that “tells” DB2 that database values read by this application are protected only while they are being used. (Changed values are protected until this application reaches the commit point). As soon as a program moves from one row to another, other programs may read or the first row.
The Data Manager is a DB2 component that manager the physical databases. It invokes other system components, as necessary, to perform detailed functions such as locking, logging, and physical I/O operations (such as search, retrieval, update, and index maintenance).
There are four buffer pools: BP0, BP1, BP2, and BP32.
It will drop(delete) that existing plan.
This is a data item that is used in an SQL statement to receive a value or to supply a value. It must be preceded by a colon (:) to tell DB2 that the variable is not a column name.
The optimizer is a DB2 component that processes SQL statements and selects the access paths.
This is the unit of storage within a table space or indexspace that is accessed by DB2.
Pagespace refers to either to an unpartitioned table, to an index space, or to a single partition of a partitioned table of index space.
A predicate is an element of a search condition that expresses or implies a comparison operation.
A recovery log is a collection of records that describes the sequence of events that occur in DB2. The information is needed for recovery in the event of a failure during execution.
Each plan is defined uniquely in the SYSIBM.SYSPLANS table to correspond to the transaction (s) that are to execute that plan.
When an application program executes with repeatable read protection, rows referenced by the program can’t be changed by other programs until the program reaches a commit point.
A STOGROUP is a named collection of DASD volumes to be used by tablespaces and index spaces of databases. The volumes of STOGROUP must be of the same device type.
This is a seven part value that consists of a date (yymmdd) and time(hhmmss and microseconds).
This is a sequence of operations within a unit of work(i.e., work done between commit points).
Exclusive, update, and share.
DB2 can be invoked by TSO users by using the DSN RUN command.
The DB2 catalog is a set of tables that contain information about all of the DB2 objects(tables, views, plans etc.).
In the RECLENGTH column of SYSIBM.SYSTABLES
The SYSIBM.SYSCOPY table contains information about image copies made of the table spaces.
Included is the name of the database, the table space name, and the image copy type(full or incremental etc.,) as well as the date and time each copy was made.
The SYSIBM.SYSLINKS table contains information about the links between tables created by referential constraints.
This information can be found in SYSIBM.SYSINDEXES.
When a view is created, system information about the view is stored in SYSIBM.SYSVIEWS.
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.
Declarations 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 data types.
A host language copy book that gives the host variable definitions for the column names.
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.
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.
No. Because the precompiler does not refer to the DB2 catalogue tables.
SQLCODE, SQLERRM, SQLERRD
Check the value stored in SQLERRD(3).
EXPLAIN is used to display the access path as determined by the optimizer for a SQL statement. It can be used in SPUFI (for single SQL statement) or in BIND step (for embedded SQL). The results of EXPLAIN is stored in U.PLAN_TABLE where U is the authorization id of the user
Make sure that the PLAN_TABLE is created under the AUTHID.
A no matching index scan if ACCESSTYPE = I.
There are two methods to achieve this:
1. Use SPUFI or QMF to EXPLAIN the dynamic SQL statement
2. Include EXPLAIN command in the embedded dynamic SQL statements
PAGE, TABLE, TABLESPACE
There are three methods to determine the lock-size. They are:
1. Based on the lock-size given while creating the table space
2. Programmer can direct the DB2 what lock-size to use
3. If lock-size ANY is specified, DB2 usually chooses a lock-size of PAGE
High resource utilization if large updates are to be done
Promoting a PAGE lock-size to table or table space lock-size when a transaction has acquired more locks than specified in NUMLKTS. Locks should be taken on objects in single table space for escalation to occur.
SHARE, EXCLUSIVE, UPDATE
No. To lock a view, take lock on the underlying tables.
SQL command used to change the definition of DB2 objects.
DBRM: Data Base 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.
Determine the point at which DB2 acquires or releases locks against table and table spaces, including intent locks.
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.
The advantages of using PACKAGE are:
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.
DATE: PIC X(10)
TIME : PIC X(08)
TIMESTAMP: PIC X(26)
PIC S9(9)V99 COMP-3.
Query the catalogue tables SYSPLANDEP and SYSPACKDEP.
CS: Cursor Stability
RR: Repeatable Read
CS: Releases the lock on a page after use.
RR: Retains all locks acquired till end of transaction
During the BIND process(ISOLATION LEVEL is a parameter for the bind process). i.e.ISOLATION ( CS/RR )
A user defined name that is the anchor for packages. It has not physical existence. Main usage is to group packages.
+100 (for successful completion of the query), 0 (for successful COMMIT if AUTOCOMMIT is set to Yes).
Print the output dataset.
Dynamic SQL is a SQL statement created at program execution time.
At run time, when the PREPARE statement is issued.
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.
Use null indicators. Syntax ... INTO :HOSTVAR:NULLIND
-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.
It is a type of index that (1) locates table rows and (2) determines how rows are grouped together in the table space.
DSNDB07 is where DB2 does its sorting. It includes DB2’s sort work area and external storage.
Use WITH HOLD option in DECLARE CURSOR statement. But, it has not effect in psuedo-conversational CICS programs.
After a load, or after mass updates, inserts, deletes, or after REORG.
Number of rows in the table, Percent of rows in clustering sequence, Number of distinct values of indexed column, Number of rows moved to a nearby/fairway page due to row length increase
REORG reorganizes data on physical storage to reclutser 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 table space have become fragmented.
It is full backup of a DB2 table which can be used in recovery.
To take routine backup of tables, After a LOAD with LOG NO and After REORG with LOG NO
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.
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.
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.
SELECT statement has resulted in retrieval of more than one row.
This is generated when the consistency tokens in the DBRM and the load module are different.
Not all of them. Some views are updatable e.g. 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.
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 one table with all the values 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.
PCTFREE: percentage of each page to be left free
FREEPAGE: Number of pages to be loaded with data between each free page
Simple Table space: Can contain one or more tables. Rows from multiple tables can be interleaved on a page under the DBA’s 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. Table space is divided into parts and each part is put in a separate VSAM dataset.
One divided by the number of distinct values of a column.
The number of distinct values a column or columns contain.
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.
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 information from programs. Alias is a global object & is available to all.
The column cannot have nulls. Use it for key fields.
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.
When a column which contains long text, e.g. remarks, notes, may have in most cases less than 50% of the maximum length.
Can lead to high space utilization if most of the values are close to maximum.
Positioning of VARCHAR column has to be done carefully as it has performance implications.
Relocation of rows to different pages can lead to more I/Os on retrieval.
At run time.
The ability to join rows and combine data from two or more tables is one of the most powerful features of relational system.
Three type of joins:
Total 16 queries and sub queries are 15
Ten 32k size buffer pools and fifty 4k size buffer pools (bp0 to bp49) default buffer pools are bp0,bp1,bp2 & bp32
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, increase the space allocation of SPUFI out file.
unique index violation
One way is to use The SQL WHERE clause.
Collection is something that every programmer should assign/Specify for every package. this about 1-18 characters long.
The Executable form of a Plan. This is stored in sysibm.sct02 table.
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.
With Hold option.
In a sub query, if the outer query refers back to the outcome of inner query it is called correlated sub query. That's why the outer query is evaluated first unlike an ordinary sub query
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.
4K to 8K
The Max length is 136. and the SQLCABC has the Value of SQLCA.
133.Usually it will be difficult monitor more than 3 or 4 volumes to a Storage group.
The answer is 18 characters.
Program name not in plan. Bind the plan and include the DBRM for the program named as part of the plan.
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.
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.
WHERE is for Rows and HAVING is for Groups
minimum is 4. maximum is 64.
DB2 bind is a process that builds an access path to DB2 tables.
An access path is the method used to access data specified in DB2 SQL statements.
An application plan or package is generated by the bind to define an access path.
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.
A view is a virtual table made up of data from base tables and other views, but not stored separately.
A 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.
Group by controls the presentation of the rows, order by controls the presentation of the columns for the results of the SELECT statement.
An embedded SQL statement may return a number of rows while the programming language can only access one row at a time. The programming device called a cursor controls the position of the row.
Referential integrity refers to the consistency that must be maintained between primary and foreign keys, i.e. every foreign key value must have a corresponding primary key value.
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.
SPUFI stands for SQL processing using file input. It is the DB2 interactive menu-driven tool used by developers to create database objects.
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.
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.
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.
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.
The cascade rule will not allow deletions based on subselect that references the same table from which the deletions are being made.
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.
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.
DB2 use the multiple indexes to satisfy multiple predicates in a SELECT statement that are joined by an AND or OR.
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.
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.
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.
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.
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.
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 tablespace or at the tablespace level for a non-segmented tablespace. They indicate at the table or tablespace 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.
The clause avoids closing the cursor and repositioning it to the last row processed when the cursor is reopened.
If there is an index on the attributes tested an IN is more efficient since DB2 uses the index for the IN.
A lock is the mechanism that controls access to data pages and tablespaces.
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 untile the transaction completes or a syncpoint is issued. For transactions using 'cursor stability' the page lock releases are issued as the cursor 'moves', i.e. as the transaction releases addressability to the records.
It is a DB2 facility for static SQL statements - it replaces these statements with calls to the DB2 language interface module
The CHECK Utility checks the referential integrity of table relations and checks the integrity of the indexes by matching index column values to table column values.
Column-name qualifier are used as table designator to avoid ambiguity when the column names referenced exist in more than one table used in the SQL statement. Column-name qualifiers are used in correlated references.
It is a special type of column designator that connects specific column in the various levels of a multilevel SQL query.
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 a qualifier of a search condition in the WHERE clause of the subquery.
A read-only cursor is one in which the result table was created by a query containing one of the following :
a DISTINCT keyword
a UNION operator
a column or scalar function
a GROUP BY clause
a ORDER BY clause
a HAVING clause
a read-only view in the FROM clause
a FROM clause identifying more than one table or view
The SYSIBM table that contain authorization information are SYSCOLAUTH, SYSDBAUTH, SYSPLANAUTH, SYSTABAUTH and SYSUSERAUTH.