CREATE DATABASE

The CREATE DATABASE statement defines a DB2® database at the current server.

Invocation

This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared only if DYNAMICRULES run behavior is implicitly or explicitly specified.

Authorization

The privilege set that is defined below must include at least one of the following:

  • The CREATEDBA privilege
  • The CREATEDBC privilege
  • SYSADM or SYSCTRL authority
  • Start of changeSystem DBADMEnd of change

Start of changeIf the database is created as a workfile database, the privilege set that is defined below must include SYSADM authority.End of change

Privilege set: If the statement is embedded in an application program, the privilege set is the privileges that are held by the owner of the plan or package.

If the statement is dynamically prepared, the privilege set is the privileges that are held by the SQL authorization ID of the process unless the process is within a trusted context and the ROLE AS OBJECT OWNER clause is specified. In that case, the privilege set is the set of privileges that are held by the role that is associated with the primary authorization ID of the process.

See Notes for the authorization effect of a successful CREATE DATABASE statement.

Syntax

Read syntax diagram
>>-CREATE DATABASE--database-name------------------------------->

   .-------------------------------------------.   
   V  (1)                                      |   
>--------+-----------------------------------+-+---------------><
         +-BUFFERPOOL--bpname----------------+     
         +-INDEXBP--bpname-------------------+     
         +-AS WORKFILE--+------------------+-+     
         |              '-FOR--member-name-' |     
         |           .-SYSDEFLT------.       |     
         +-STOGROUP--+-stogroup-name-+-------+     
         '-CCSID--+-ASCII---+----------------'     
                  +-EBCDIC--+                      
                  '-UNICODE-'                      

Notes:
  1. The same clause must not be specified more than one time.

Description

database-name
Names the database. The name must not start with DSNDB and must not identify a database that exists at the current server. database-name must not be in the form of eight characters that start with DSN followed by exactly five digits. If the database is to be a work file database in a data sharing environment, DSNDB07 is an acceptable work file database name. However, only one member of a data sharing group can use DSNDB07 as the name of its work file database.
BUFFERPOOL bpname
Specifies the default buffer pool name to be used for table spaces created within the database. If the database is a work file database, 8KB and 16KB buffer pools cannot be specified. See Naming conventions for more details about bpname.

If you omit the BUFFERPOOL clause, the buffer pool for the TBSBPOOL subsystem parameter value is used. If the table space is implicitly created, DB2 selects the buffer pool as described in Implicitly defined table spaces.

INDEXBP bpname
Specifies the default buffer pool name to be used for the indexes created within the database. The name can identify a 4KB, 8KB, 16KB, or 32KB buffer pool. See Naming conventions for more details about bpname.

If you omit the INDEXBP clause, the buffer pool specified for user indexes on installation panel DSNTIP1 is used. The default value for the user indexes field on that panel is BP0.

AS WORKFILE
Specifies the database is a work file database. AS WORKFILE can be specified only in a data sharing environment. Only one work file database can be created for each DB2 subsystem. The work file database is used for work files, created global temporary table, declared temporary tables, and sensitive static scrollable cursors.

PUBLIC implicitly receives the CREATETAB privilege (without GRANT authority) to define a declared temporary table in the work file database. This implicit privilege is not recorded in the DB2 catalog and cannot be revoked.

The CCSID clause is not supported for a work file database. If you specify AS WORKFILE, do not use the CCSID clause.

FOR member-name
Specifies the member for which this database is to be created. Specify FOR member-name only in a data sharing environment.

If FOR member-name is not specified, the member is the DB2 subsystem on which the CREATE DATABASE statement is executed.

STOGROUP stogroup-name
Specifies the storage group to be used, as required, as a default storage group to support DASD space requirements for table spaces and indexes within the database. The default is SYSDEFLT.
CCSID encoding-scheme
Specifies the default encoding scheme for data stored in the database. The default applies to table spaces created in the database. All tables stored within a table space must use the same encoding scheme.
ASCII
Specifies that the data must be encoded using the ASCII CCSIDs of the server.
EBCDIC
Specifies that the data must be encoded using the EBCDIC CCSIDs of the server.
UNICODE
Specifies that the data must be encoded using the UNICODE CCSIDs of the server.

Usually, each encoding scheme requires only a single CCSID. Additional CCSIDs are needed when mixed, graphic, or UNICODE data is used.

The option defaults to the value of field DEF ENCODING SCHEME on installation panel DSNTIPF.

Do not use the CCSID clause if you specify the AS WORKFILE clause.

Notes

If the statement is embedded in an application program, the owner of the plan or package is the owner of the database. If the statement is dynamically prepared, the SQL authorization ID of the process is the owner of the database.

If the owner of the database has the CREATEDBA, SYSADM, or SYSCTRL authority, the owner acquires DBADM authority for the database. DBADM authority for a database includes table privileges on all tables in that database. Thus, if a user with SYSCTRL authority creates a database, that user has table privileges on all tables in that database. This is an exception to the rule that SYSCTRL authority does not include table privileges.

If the owner of the database has the CREATEDBC privilege, but not the CREATEDBA privilege, the owner acquires DBCTRL authority for the database. In this case, no authorization ID has DBADM authority for the database until it is granted by an authorization ID with SYSADM authority.

Examples

Example 1: Create database DSN8D10P. Specify DSN8G100 as the default storage group to be used for the table spaces and indexes in the database. Specify 8KB buffer pool BP8K1 as the default buffer pool to be used for table spaces in the database, and BP2 as the default buffer pool to be used for indexes in the database.
   CREATE DATABASE DSN8D10P
     STOGROUP DSN8G100
     BUFFERPOOL BP8K1
     INDEXBP BP2;
Example 2: Create database DSN8TEMP. Use the defaults for the default storage group and default buffer pool names. Specify ASCII as the default encoding scheme for data stored in the database.
   CREATE DATABASE DSN8TEMP
     CCSID ASCII;