← All languages
SQL keyword of the day
Random

CREATE DATABASE

Create a new database.

Description

CREATE DATABASE creates a new database within the current server. The new database starts empty (or as a copy of a template, depending on the dialect) and a separate connection is normally needed to use it.

Most dialects support clauses for the owner, character set, collation, and tablespace. PostgreSQL allows TEMPLATE to clone an existing database, MySQL accepts CHARACTER SET and COLLATE, and SQL Server offers ON and LOG ON to control file placement.

The statement requires server-level privileges and typically cannot run inside a transaction. It is the first step in setting up a new application's persistent storage.

Arguments

NameDescriptionOptional
name The identifier for the new database. No
OWNER user Assign ownership of the database to the named user (PostgreSQL). Yes
CHARACTER SET / COLLATE Specify the default character set and collation for the database. Yes

Example

CREATE DATABASE shop;

CREATE DATABASE shop
  OWNER = app_user
  TEMPLATE = template0
  ENCODING = 'UTF8';

Reference