O'Reilly logo

SQL in a Nutshell by Kevin Kline

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required