SQL CREATE DATABASE Statement
Learn how to use SQL CREATE DATABASE to create an empty database, understand its syntax, permissions, naming rules, and next steps.
The CREATE DATABASE statement creates a new database in a database management system (DBMS). A database is an organized container for related data and objects such as tables, views, indexes, and stored routines.
You can create a database by executing SQL, or by using a graphical database administration tool or command-line utility. The interface differs, but the underlying operation is the same: a database container is created on the server or platform.
What Is a DBMS?
A DBMS, or Database Management System, is software that stores, manages, and provides access to databases. Examples include MySQL, PostgreSQL, SQL Server, Oracle, SQLite, and cloud database services.
SQL syntax and administration features vary between DBMS products. The basic statement is widely recognized, but optional clauses, permissions, and connection commands are product-specific.
Basic CREATE DATABASE Syntax
CREATE DATABASE database_name;
| Element | Meaning |
|---|---|
CREATE DATABASE | Keywords that tell the DBMS to create a new database. |
database_name | The identifier chosen for the new database. |
; | A statement terminator used by many SQL tools and DBMSs. |
SQL keywords are commonly written in uppercase for readability, although many DBMSs do not require that capitalization. Replace database_name with the name you want to assign to the database.
Creating a Database
CREATE DATABASE Mydatabase;
After successful execution, the DBMS creates a new, empty database named Mydatabase. The statement does not automatically create tables, rows, views, or other application objects. Those must be added separately.
For example, after connecting to or selecting the new database, the next step might be:
CREATE TABLE customers (id INT, name VARCHAR(100));
The exact command used to connect to or select a database depends on the DBMS and the SQL client. See the SQL CREATE TABLE statement lesson for table syntax.
Database Names and Identifiers
A database name is an identifier: the name by which the DBMS refers to the database. Valid names depend on the selected DBMS and its configuration.
- Choose a meaningful, consistent name such as
sales_apporinventory. - Avoid reserved words and names that could be confused with commands or system objects.
- Follow the DBMS rules for length, character set, spaces, and case sensitivity.
- When a name contains special characters or conflicts with a keyword, the DBMS may require identifier delimiters. The delimiter style is DBMS-specific.
Simple names containing letters, numbers, and underscores are usually easier to use in scripts and administration tools than names containing spaces or punctuation.
Permissions Required
The account executing CREATE DATABASE needs the appropriate privilege. A privilege is permission granted to a user or role to perform an action.
On some systems, only an administrator or another highly privileged account can create databases. In managed or cloud environments, database creation may instead be controlled through a provider console, server command, deployment system, or separate administrative role.
DBMS and Tool Considerations
Although the basic form is common, database creation is not completely portable. MySQL, PostgreSQL, SQL Server, Oracle, SQLite, and cloud database platforms can differ in supported clauses, naming rules, ownership, storage settings, character sets, templates, and administrative workflows.
| Consideration | Why it matters |
|---|---|
| Required privileges | The current user may not be authorized to create a database. |
| Database naming rules | Names, lengths, reserved words, and identifier delimiters differ by DBMS. |
| DBMS-specific options | Optional clauses and settings are not interchangeable between products. |
| Selecting or connecting to the database | A new database may not become the active database automatically. |
Graphical administration tools often provide fields for these product-specific options and may perform additional validation. SQL scripts are useful for repeatable, automated setup, while a graphical tool can help beginners inspect available servers, users, and databases.
What to Do After Creation
- Confirm that the database was created successfully.
- Connect to, select, or switch to the new database using the method required by your DBMS.
- Create tables and define their columns with
CREATE TABLE. - Add constraints, indexes, views, routines, and data as needed.
Creating the database and creating its tables are separate operations. A database can exist successfully while remaining empty.
Troubleshooting
Permission denied or insufficient privilege
Likely cause: The current account is not authorized to create databases.
Resolution: Use an account with the required administrative permission, or ask an administrator to grant the appropriate database-creation privilege according to local policy.
Database already exists
Likely cause: A database with the requested name already exists on the server.
Resolution: Choose another name, verify whether the existing database is the intended one, or use a conditional creation feature only if your DBMS supports it and that behavior is appropriate. Avoid deleting an existing database just to repeat a setup script.
Syntax error
Likely cause: The statement does not match the selected DBMS, or the identifier is invalid.
Resolution: Check the DBMS syntax, confirm that the name follows its rules, and apply the correct identifier delimiters when needed. Optional clauses from one DBMS cannot automatically be used in another.
Tables cannot be created afterward
Likely cause: The session is still connected to another database or has not selected the newly created one.
Resolution: Connect to or select the new database before running CREATE TABLE. Also verify that the account has permission to create tables in that database.
Key Points
CREATE DATABASE database_name;creates a database container.- The new database is generally empty; tables and other objects are created separately.
- The executing account needs the required database-creation privilege.
- Naming rules, optional clauses, and connection commands vary by DBMS.
- After creation, select or connect to the database before creating its tables.
For related SQL fundamentals, review what SQL is and SQL syntax. To remove a database or another database object, study the SQL DROP statement carefully because deletion can be destructive.