HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

CREATE DATABASE

Function

Create a new database. By default new databases will be created by copying the standard system database template0, and creation using template0 is only supported.

Create a new schema. The default character set and character order of the schema can be set.

Precautions

Compared to the original MogDB, dolphin's changes to the CREATE DATABASE syntax are:

  • Add modifiable items [ [DEFAULT] CHARACTER SET | CHARSET [ = ] default_charset ] [ [DEFAULT] COLLATE [ = ] default_collation ].

Syntax

CREATE DATABASE [IF NOT EXISTS] database_name
               [ [DEFAULT] CHARACTER SET | CHARSET [ = ] default_charset ] [ [DEFAULT] COLLATE [ = ] default_collation ];

Parameter Description

  • database_name

    The name of the database.

    Range of values: string, to conform to the naming convention for identifiers.

  • [ [DEFAULT] CHARACTER SET | CHARSET [ = ] default_charset ]

    Specifies the default character set for the schema, which when specified alone sets the default character order of the schema to the default character order of the specified character set.

  • [ [DEFAULT] COLLATE [ = ] default_collation ]

    Specifies the default collation for the schema, which when specified alone sets the default collation for the schema to the character set corresponding to the specified collation.

    imgNote:

    • With B compatibility, this syntax is only supported if dolphin.b_compatibility_mode is on.
    • When this syntax is used, the syntax is equivalent to CREATE SCHEMA, which is the actual SCHEMA creation syntax, and database_name is the SCHEMA name.
    • B compatibility, dolphin.b_compatibility_mode is on, do not specify default_charset, default_collation, but specify other CREATE DATABASE syntax options, the syntax is still CREATE DATABASE syntax.
    • Under B-compatibility, when dolphin.b_compatibility_mode is on, and no option is specified, the syntax is equivalent to CREATE SCHEMA syntax; when dolphin.b_compatibility_mode is off, the syntax is equivalent to CREATE DATABASE syntax.

Examples

-- Enable the dolphin.b_compatibility_mode
MogDB=# set dolphin.b_compatibility_mode = on;
SET
MogDB=# create database test1;
CREATE SCHEMA
MogDB=# create database test2 charset 'utf8';
CREATE SCHEMA
MogDB=# drop database if exists test1;

ALTER DATABASE, DROP DATABASE, CREATE DATABASE

Copyright © 2011-2024 www.enmotech.com All rights reserved.