Creation of databases

When you define a Db2 database, you name an eventual collection of tables, associated indexes, and the table spaces in which they are to reside.

When you decide whether to define a new database for a new set of objects or use an existing database, consider the following facts:

  • You can start and stop an entire database as a unit. You can display the status of all objects in the database by using a single command that names only the database. Therefore, place a set of related tables into the same database. (The same database holds all indexes on those tables.)
  • If you want to improve concurrency and memory use, keep the number of tables in a single database relatively small (maximum of 20 tables). For example, with fewer tables, Db2 performs a reorganization in a shorter length of time.
  • Having separate databases allows data definitions to run concurrently and also uses less space for control blocks.

To create a database, use the CREATE DATABASE statement. A name for a database is an unqualified identifier of up to eight characters. A Db2 database name must not be the same as the name of any other Db2 database.

Implicit creation of databases

If you do not specify the IN clause in a CREATE TABLE statement, Db2 implicitly creates a database.

The name of the database is DSNxxxxx, where xxxxx is the next five-digit number from a sequence, for example:

DSN00001, DSN00002, DSN00003, ...

However, if you do not specify the IN clause in a CREATE TABLESACE statement, the table space is created in database DSNDB04.

Example

Begin general-use programming interface information.The following example shows a valid database name:
Object
Name
Database
MYDB
This CREATE DATABASE statement creates the database MYDB:
CREATE DATABASE MYDB
  STOGROUP MYSTOGRP
  BUFFERPOOL BP8K4
  INDEXBP BP4;

The STOGROUP, BUFFERPOOL, and INDEXBP clauses that this example shows establish default values. You can override these values on the definitions of the table space or index space. End general-use programming interface information.