Name

CREATE/ALTER DATABASE Statement

Synopsis

The ANSI standard does not actually contain a CREATE DATABASE statement. However, since it is nearly impossible to operate a SQL database without this command, we’ve added CREATE DATABASE here. Almost all database platforms support some version of this command.

Platform

Command

DB2

Supported, with variations

MySQL

Supported, with variations

Oracle

Supported, with variations

PostgreSQL

Supported, with variations

SQL Server

Supported, with variations

Rules at a Glance

This command creates a new, blank database with a specific name. Most DBMS platforms require the user to possess administrator privileges in order to create a new database. Once the new database is created, you can populate it with database objects (such as tables, views, triggers, and so on) and populate the tables with data.

Depending on the platform, CREATE DATABASE may also create corresponding files on the filesystem that contain the data and metadata of the database.

Programming Tips and Gotchas

Since CREATE DATABASE is not an ANSI command, it is prone to rather extreme variation in syntax between platforms.

DB2

The DB2 statement CREATE DATABASE initializes a new database with a variety of user-defined characteristics, such as collation and autoconfiguration options. In addition, the statement also creates the three initial tablespaces, system tables, and recovery logs required by a DB2 database:

CREATE {DATABASE | DB} database_name
[AT DBPARITIONNUM] [ON path_and_drive ...

Get SQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.