Ten artykuł zawiera SQL CREATE DATABASE
składnia, zaimplementowana przez różne systemy zarządzania bazami danych (DBMS). Składnia jest podana dokładnie tak, jak każdy dostawca podał ją na swojej stronie internetowej. Kliknij odpowiedni link, aby wyświetlić więcej szczegółów na temat składni konkretnego dostawcy.
Omówione DBMS to MySQL, SQL Server, PostgreSQL i Oracle Database.
MySQL
Z podręcznika MySQL 5.7 Reference:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS]db_name
[create_specification
] ...create_specification
: [DEFAULT] CHARACTER SET [=]charset_name
| [DEFAULT] COLLATE [=]collation_name
Serwer SQL
Z dokumentacji Transact-SQL:
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
Z podręcznika PostgreSQL 9.5:
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 ]
Baza danych Oracle
Z dokumentacji online bazy danych Oracle 12c Wydanie 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 }... ;
Poniżej przedstawiono szczegóły różnych klauzul.
database_logging_clauses
{ LOGFILE [ GROUP integer ] file_specification [, [ GROUP integer ] file_specification ]... | MAXLOGFILES integer | MAXLOGMEMBERS integer | MAXLOGHISTORY integer | { ARCHIVELOG | NOARCHIVELOG } | FORCE LOGGING }
klauzule_tablespace
{ 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 }...
Standard SQL
Pamiętaj, że nie ma opcji CREATE DATABASE
oświadczenie w oficjalnym standardzie SQL. Standard SQL pozostawia dostawcom określenie, w jaki sposób konkretna implementacja utworzy bazę danych.
Korzystanie z GUI
Bazy danych można również tworzyć za pomocą graficznego interfejsu użytkownika w każdym z systemów zarządzania bazami danych lub za pomocą dowolnego narzędzia graficznego dostępnego do użytku z tym produktem.
Na przykład możesz utworzyć bazę danych za pomocą GUI podczas pracy z MySQL Workbench.