DB2® databases are
a set of DB2 structures
that include a collection of tables, their associated indexes, and
the table spaces in which they reside. You define a database by using
the CREATE DATABASE statement.
Whenever a table space is created, it is explicitly
or implicitly assigned to an existing database. If you create a table
space and do not specify a database name, the table space is created
in the default database, DSNDB04. In this case, DB2 implicitly creates
a database or uses an existing implicitly created database for the
table. All users who have the authority to create table spaces or
tables in database DSNDB04 have authority to create tables and table
spaces in an implicitly created database. If the table space is implicitly
created, and you do not specify the IN clause in the CREATE TABLE
statement, DB2 implicitly
creates the database to which the table space is assigned.![End of change](./deltaend.gif)
A
single database, for example, can contain all the data that is
associated with one application or with a group of related applications.
Collecting that data into one database allows you to start or stop
access to all the data in one operation. You can also grant authorization
for access to all the data as a single unit. Assuming that you are
authorized to access data, you can access data that is stored in different
databases.
Recommendation: ![Start of change](./delta.gif)
Avoid
using a single database for a large number of tables. As a general
rule, you should have only one table in each database. If you must
have more than one table in a database, keep no more than 20 tables
in that database. Defining one database for each table improves performance,
availability, and manageability.
![End of change](./deltaend.gif)
The following figure shows
how the main DB2 data
structures
fit together. Two databases, A and B, are represented as squares.
Database A contains a table space and two index spaces. The table
space is segmented and contains tables A1 and A2. Each index space
contains one index, an index on table A1 and an index on table A2.
Database B contains one table space and one index space. The table
space is partitioned and contains table B1, partitions 1 through 4.
The index space contains one partitioning index, parts 1 to 4.
Figure 1. Data structures
in a DB2 database
When you migrate to the current version, DB2 adopts the default
database and default storage group that you used in the previous version.
You have the same authority for the current version as you did in
the previous version.![End of change](./deltaend.gif)
Declared global temporary tables
are now stored in the WORKFILE database. The TEMP database is no longer
used.![End of change](./deltaend.gif)
Reasons to define a database
In DB2 for z/OS®, a database is a logical collection of
table spaces and index spaces. Consider the following factors when
deciding whether to define a new database for a new set of objects:
- You can start and stop an entire database as a unit; you can display
the statuses of all its objects by using a single command that names
only the database. Therefore, place a set of tables that are used
together into the same database. (The same database holds all indexes
on those tables.)
- Some operations lock an entire database.
For example, some phases
of the LOAD utility prevent some SQL statements (CREATE, ALTER, and
DROP) from using the same database concurrently. Therefore, placing
many unrelated tables in a single database is often inconvenient.
When
one user is executing a CREATE, ALTER, or DROP statement for a table,
no other user can access the database that contains that table. QMF™ users, especially, might do a
great deal of data definition; the QMF operations
SAVE DATA and ERASE data-object are accomplished
by creating and dropping DB2 tables. For
maximum concurrency, create a separate database for each QMF user.
- The internal database descriptors
(DBDs) might become inconveniently
large. DBDs grow as new objects are defined, but they do not immediately
shrink when objects are dropped; the DBD space for a dropped object
is not reclaimed until the MODIFY RECOVERY utility is used to delete
records of obsolete copies from SYSIBM.SYSCOPY. DBDs occupy storage
and are the objects of occasional input and output operations. Therefore,
limiting the size of DBDs is another reason to define new databases.