Creating a Database

Function

This statement is used to create a database.

Syntax

1
2
3
CREATE [DATABASE | SCHEMA] [IF NOT EXISTS] db_name
  [COMMENT db_comment]
  [WITH DBPROPERTIES (property_name=property_value, ...)];

Keyword

  • IF NOT EXISTS: Prevents system errors if the database to be created exists.
  • COMMENT: Describes a database.
  • DBPROPERTIES: Specifies database attributes. The attribute name and attribute value appear in pairs.

Precautions

  • DATABASE and SCHEMA can be used interchangeably. You are advised to use DATABASE.
  • The default database is a built-in database. You cannot create a database named default.

Example

If database testdb does not exist, run the following statement to create database testdb:

1
CREATE DATABASE IF NOT EXISTS testdb;