This article contains the SQL CREATE DATABASE
syntax, as implemented by various database management systems (DBMSs). The syntax is listed exactly as each vendor has listed it on their website. Click on the applicable link to view more detail about the syntax for a particular vendor.
The DBMSs covered are MySQL, SQL Server, PostgreSQL, and Oracle Database.
MySQL
From the MySQL 5.7 Reference Manual:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS]db_name
[create_specification
] ...create_specification
: [DEFAULT] CHARACTER SET [=]charset_name
| [DEFAULT] COLLATE [=]collation_name
SQL Server
From the Transact-SQL Reference:
CREATE DATABASE database_name [ CONTAINMENT = { NONE | PARTIAL } ] [ ON [ PRIMARY ] <filespec> [ ,...n ] [ , <filegroup> [ ,...n ] ] [ LOG ON <filespec> [ ,...n ] ] ] [ COLLATE collation_name ] [ WITH <option> [,...n ] ] [;] <option> ::= { FILESTREAM ( <filestream_option> [,...n ] ) | DEFAULT_FULLTEXT_LANGUAGE = { lcid | language_name | language_alias } | DEFAULT_LANGUAGE = { lcid | language_name | language_alias } | NESTED_TRIGGERS = { OFF | ON } | TRANSFORM_NOISE_WORDS = { OFF | ON} | TWO_DIGIT_YEAR_CUTOFF = <two_digit_year_cutoff> | DB_CHAINING { OFF | ON } | TRUSTWORTHY { OFF | ON } } <filestream_option> ::= { NON_TRANSACTED_ACCESS = { OFF | READ_ONLY | FULL } | DIRECTORY_NAME = 'directory_name' } To attach a database CREATE DATABASE database_name ON <filespec> [ ,...n ] FOR { { ATTACH [ WITH <attach_database_option> [ , ...n ] ] } | ATTACH_REBUILD_LOG } [;] <filespec> ::= { ( NAME = logical_file_name , FILENAME = { 'os_file_name' | 'filestream_path' } [ , SIZE = size [ KB | MB | GB | TB ] ] [ , MAXSIZE = { max_size [ KB | MB | GB | TB ] | UNLIMITED } ] [ , FILEGROWTH = growth_increment [ KB | MB | GB | TB | % ] ] ) } <filegroup> ::= { FILEGROUP filegroup_name [ CONTAINS FILESTREAM ] [ DEFAULT ] <filespec> [ ,...n ] } <attach_database_option> ::= { <service_broker_option> | RESTRICTED_USER | FILESTREAM ( DIRECTORY_NAME = { 'directory_name' | NULL } ) } <service_broker_option> ::= { ENABLE_BROKER | NEW_BROKER | ERROR_BROKER_CONVERSATIONS } Create a database snapshot CREATE DATABASE database_snapshot_name ON ( NAME = logical_file_name, FILENAME = 'os_file_name' ) [ ,...n ] AS SNAPSHOT OF source_database_name [;]
PostgreSQL
From the PostgreSQL 9.5 Manual:
CREATE DATABASE name [ [ WITH ] [ OWNER [=] user_name ] [ TEMPLATE [=] template ] [ ENCODING [=] encoding ] [ LC_COLLATE [=] lc_collate ] [ LC_CTYPE [=] lc_ctype ] [ TABLESPACE [=] tablespace_name ] [ ALLOW_CONNECTIONS [=] allowconn ] [ CONNECTION LIMIT [=] connlimit ] ] [ IS_TEMPLATE [=] istemplate ]
Oracle Database
From the Oracle Database Online Documentation 12c Release 1 (12.1):
CREATE DATABASE [ database ] { USER SYS IDENTIFIED BY password | USER SYSTEM IDENTIFIED BY password | CONTROLFILE REUSE | MAXDATAFILES integer | MAXINSTANCES integer | CHARACTER SET charset | NATIONAL CHARACTER SET charset | SET DEFAULT { BIGFILE | SMALLFILE } TABLESPACE | database_logging_clauses | tablespace_clauses | set_time_zone_clause | [ BIGFILE | SMALLFILE ] USER_DATA TABLESPACE tablespace_name DATAFILE datafile_tempfile_spec [, datafile_tempfile_spec ]... | enable_pluggable_database }... ;
The following outlines the detail of the various clauses.
database_logging_clauses
{ LOGFILE [ GROUP integer ] file_specification [, [ GROUP integer ] file_specification ]... | MAXLOGFILES integer | MAXLOGMEMBERS integer | MAXLOGHISTORY integer | { ARCHIVELOG | NOARCHIVELOG } | FORCE LOGGING }
tablespace_clauses
{ EXTENT MANAGEMENT LOCAL | DATAFILE file_specification [, file_specification ]... | SYSAUX DATAFILE file_specification [, file_specification ]... | default_tablespace | default_temp_tablespace | undo_tablespace }
default_tablespace
DEFAULT TABLESPACE tablespace [ DATAFILE datafile_tempfile_spec ] [ extent_management_clause ]
default_temp_tablespace
[ BIGFILE | SMALLFILE ] DEFAULT TEMPORARY TABLESPACE tablespace [ TEMPFILE file_specification [, file_specification ]...] [ extent_management_clause ]
extent_management_clause
EXTENT MANAGEMENT LOCAL [ AUTOALLOCATE | UNIFORM [ SIZE size_clause ] ]
undo_tablespace
[ BIGFILE | SMALLFILE ] UNDO TABLESPACE tablespace [ TABLESPACE file_specification [, file_specification ]...]
set_time_zone_clause
SET TIME_ZONE = '{ { + | - } hh : mi | time_zone_region }'
enable_pluggable_database
ENABLE PLUGGABLE DATABASE [ SEED [ file_name_convert ] [ SYSTEM tablespace_datafile_clauses ] [ SYSAUX tablespace_datafile_clauses ] ]
file_name_convert
FILE_NAME_CONVERT = { ( 'filename_pattern', 'replacement_filename_pattern' [, 'filename_pattern', 'replacement_filename_pattern' ]... ) | NONE }
tablespace_datafile_clauses
DATAFILES { SIZE size_clause | autoextend_clause }...
SQL Standard
Note that there is no CREATE DATABASE
statement in the official SQL standard. The SQL standard leaves it up to vendors to define how a particular implementation will create a database.
Using the GUI
Creating databases can also be done via the GUI in each of the database management systems, or by using any of the GUI tools available for use with that product.
For example, you can create a database via the GUI when working with MySQL Workbench.