Dieser Artikel enthält die SQL CREATE DATABASE
Syntax, wie sie von verschiedenen Datenbankverwaltungssystemen (DBMSs) implementiert wird. Die Syntax wird genau so aufgeführt, wie sie jeder Anbieter auf seiner Website aufgeführt hat. Klicken Sie auf den entsprechenden Link, um weitere Einzelheiten zur Syntax für einen bestimmten Anbieter anzuzeigen.
Die behandelten DBMS sind MySQL, SQL Server, PostgreSQL und Oracle Database.
MySQL
Aus dem MySQL 5.7 Referenzhandbuch:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS]db_name
[create_specification
] ...create_specification
: [DEFAULT] CHARACTER SET [=]charset_name
| [DEFAULT] COLLATE [=]collation_name
SQL-Server
Aus der Transact-SQL-Referenz:
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
Aus dem PostgreSQL 9.5-Handbuch:
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-Datenbank
Aus der Oracle Database Online Documentation 12c Version 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 }... ;
Im Folgenden werden die Einzelheiten der verschiedenen Klauseln beschrieben.
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
Beachten Sie, dass es kein CREATE DATABASE
gibt -Anweisung im offiziellen SQL-Standard. Der SQL-Standard überlässt es den Anbietern zu definieren, wie eine bestimmte Implementierung eine Datenbank erstellt.
Verwendung der GUI
Das Erstellen von Datenbanken kann auch über die GUI in jedem der Datenbankverwaltungssysteme oder mit einem der GUI-Tools erfolgen, die für die Verwendung mit diesem Produkt verfügbar sind.
Beispielsweise können Sie eine Datenbank über die GUI erstellen, wenn Sie mit MySQL Workbench arbeiten.