Mainframe Path Start learning free
Core6 min readLesson 1 of 4

What DB2 for z/OS is

DB2 is a relational database that runs as a set of address spaces under z/OS. The SQL is standard enough that anything you know from other databases transfers. What is different is how programs get connected to it, and how seriously it takes concurrency at very high volumes.

The pieces

How DB2 is organised
SubsystemA named DB2 instance, e.g. DBP1 — several address spaces working together
DatabaseA logical grouping of table spaces and index spaces
Table spaceThe physical storage holding one or more tables
TableRows and columns, as you would expect
IndexA separate structure making lookups fast

Where you will meet it

The catalog: DB2 describing itself

DB2 keeps its own metadata in ordinary tables you can query. This is unreasonably useful and underused by beginners.

Questions you can answer with SQL alone
-- what columns does this table have?
SELECT NAME, COLTYPE, LENGTH, SCALE, NULLS
  FROM SYSIBM.SYSCOLUMNS
 WHERE TBNAME = 'ACCOUNT' AND TBCREATOR = 'PAYPROD'
 ORDER BY COLNO;

-- which programs use this table?
SELECT DISTINCT DNAME, DTYPE
  FROM SYSIBM.SYSPACKDEP
 WHERE BNAME = 'ACCOUNT';

-- what indexes exist on it?
SELECT NAME, UNIQUERULE, COLCOUNT
  FROM SYSIBM.SYSINDEXES
 WHERE TBNAME = 'ACCOUNT';

Common mistakes

Assuming DB2 for z/OS is identical to Db2 on other platforms

The SQL is close, but packaging, binding, utilities and tuning differ significantly.

Running an unrestricted SELECT against a production table

A table with billions of rows will happily try to return them all. Always constrain, and use FETCH FIRST n ROWS ONLY when exploring.

What you will see at work

Key terms

Check your understanding.
Take this lesson's quiz and save your progress. Free.

Take the lesson quiz
Embedded SQL, precompile and BIND →