DB2 - Create Database




DB2 Create Database

CREATE DATABASE command is used to create a database in an instance. All databases are created with the default storage group "IBMSTOGROUP", which is created at the time of creating an instance. In DB2, all the database tables are stored in "tablespace", which use their respective storage groups.

The CREATE DATABASE command initializes a new database with an optional user-defined collating sequence, creates the three initial table spaces, creates the system tables, and allocates the recovery log file. When you initialize a new database, the AUTOCONFIGURE command is issued by default.

The Triple Data Encryption Standard (3DES) native encryption option is deprecated and might be removed in a future release. We recommend that you now use the Advanced Encryption Standard (AES) native encryption option.

When the instance and database directories are created by the Db2® database manager, the permissions are accurate and should not be changed.

What is DB2 Create Database ?

When the CREATE DATABASE command is issued, the Configuration Advisor also runs automatically. This means that the database configuration parameters are automatically tuned for you according to your system resources. In addition, Automated Runstats is enabled. To disable the Configuration Advisor from running at database creation, refer to the DB2_ENABLE_AUTOCONFIG_DEFAULT registry variable. To disable Automated Runstats, refer to the auto_runstats database configuration parameter.

Adaptive Self Tuning Memory is also enabled by default for single partition databases. To disable Adaptive Self Tuning Memory by default, refer to the self_tuning_mem database configuration parameter. For multi-partition databases, Adaptive Self Tuning Memory is disabled by default.

If no code set is specified on the CREATE DATABASE command, then the collations that are allowed are: SYSTEM, IDENTITY_16BIT, language-aware-collation, and locale-sensistive-collation (SQLCODE -1083). The default code set for a database is UTF-8. If a particular code set and territory is needed for a database, the required code set and territory should be specified in the CREATE DATABASE command.

This command is not valid on a client -

Scope

In a partitioned database environment, this command affects all database partitions that are listed in the db2nodes.cfg file. The database partition from which this command is issued becomes the catalog database partition for the new database.

Required connection

Instance. To create a database at another (remote) database partition server, you must first attach to that server. A database connection is temporarily established by this command during processing.

db2 create database command is used to create a non-restrictive database.

Syntax

db2 create database <database name>

Example

let's create a database named "XYZ"  

After installation, you have to switch to that user to have rights to create a new database. Depending on the version you installed, that username might be changed. But DB2 uses db2inst1 by default as administrator user.

Syntax

CREATE [OR REPLACE] {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
    [create_specification] ...

create_specification:
    [DEFAULT] CHARACTER SET [=] charset_name
  | [DEFAULT] COLLATE [=] collation_name
  | COMMENT [=] 'comment'

Description

CREATE DATABASE creates a database with the given name. To use this statement, you need the CREATE privilege for the database. CREATE SCHEMA is a synonym for CREATE DATABASE. For valid identifiers to use as database names, see Identifier Names.