The DATABASE keyword represents operations that act on a whole logical database rather than on individual tables or schemas. Vendors expose these operations through statements such as CREATE DATABASE, ALTER DATABASE, DROP DATABASE, and USE (to switch the current database). Although the exact options differ by vendor, the core behavior is consistent: a database is created in the server catalog, optional properties (owner, encoding, collation, file location) can be changed later, it can be removed entirely, and a session can be pointed to it so unqualified object references resolve inside that database.Caveats:- In the SQL standard, CREATE SCHEMA is defined, while CREATE DATABASE remains vendor specific.- Dropping a database is irreversible; all contained objects are deleted.- Some engines (SQLite) implement the concept through ATTACH/DETACH rather than CREATE DATABASE.- Permissions to execute DATABASE statements are typically restricted to super-users or admins.
- database_name
(identifier) - Name of the database to act upon- option
(varies) - Optional settings like OWNER, ENCODING, LC_COLLATE, CHARACTER SET, FILEGROUP, MAXSIZE, etc.- IF EXISTS
(keyword, optional) - Suppresses an error if the specified database does not exist when dropping.CREATE DATABASE, ALTER DATABASE, DROP DATABASE, USE, SCHEMA, CREATE SCHEMA, GRANT
Vendor implementations; popularized in MySQL 3.23 (1998) and SQL Server 2000
Most systems require superuser, sysadmin, or the CREATEDB privilege. Regular users cannot create databases unless explicitly granted.
CREATE DATABASE creates an entirely new catalog. CREATE SCHEMA defines a namespace inside an existing database. Some vendors map databases to schemas (e.g., Snowflake).
SQLite databases are individual files. Instead of CREATE DATABASE, you use ATTACH DATABASE to open another file in the same session.
Renaming is vendor specific. PostgreSQL supports ALTER DATABASE RENAME TO, while MySQL requires creating a new database and migrating objects.