đī¸ The CREATE DATABASE statement is a Data Definition Language (DDL) command used to create a new database in a Database Management System (DBMS). A database serves as a container that stores tables, views, indexes, procedures, and other database objects.
đ What is CREATE DATABASE?
Before you can create tables or store data, you must first create a database. The CREATE DATABASE statement allocates a new database with a unique name, where all related objects and data can be organized.
Information
đ¯ Why Use CREATE DATABASE?
Every application typically stores its data inside one or more databases.
- đ Create a dedicated storage area for application data.
- đ Organize related tables and database objects.
- đ Separate development, testing, and production environments.
- đ Improve data management and security.
- đ Support multiple independent applications on one server.
đ Basic Syntax
CREATE DATABASE Syntax
CREATE DATABASE database_name;đĄ Create a New Database
Create a database named UniversityDB.
Create a Database
CREATE DATABASE UniversityDB;After executing the statement successfully, the database UniversityDB is created and is ready to store tables and other database objects.
đ Selecting the Database
After creating a database, you usually select it before creating tables.
Use a Database (MySQL)
USE UniversityDB;Important
đĄī¸ Create a Database Only If It Doesn't Exist
Some database systems support creating a database only when it does not already exist.
CREATE DATABASE IF NOT EXISTS
CREATE DATABASE IF NOT EXISTS UniversityDB;Tip
đ What Happens After Creation?
| Step | Result |
|---|---|
| Create Database | A new database container is created. |
| Select Database | The database becomes the current working database. |
| Create Tables | Tables and other objects can now be added. |
| Insert Data | Records can be stored inside the tables. |
đĻ Example Workflow
The following example creates a database, selects it, and creates a table.
Create Database and Table
CREATE DATABASE UniversityDB;
USE UniversityDB;
CREATE TABLE Students
(
StudentID INT PRIMARY KEY,
Name VARCHAR(100),
Department VARCHAR(100)
);âī¸ CREATE DATABASE vs CREATE TABLE
| Feature | CREATE DATABASE | CREATE TABLE |
|---|---|---|
| Creates | A database. | A table. |
| Contains Data | â No | â Yes |
| Purpose | Store database objects. | Store records. |
| Execution Order | First | After a database exists. |
đŧ Real-World Example
A software company is developing a Student Management System. Before creating tables such as Students, Courses, and Enrollments, it first creates a dedicated database.
Student Management Database
CREATE DATABASE StudentManagementDB;â ī¸ Database-Specific Notes
| Database System | Notes |
|---|---|
| MySQL | Supports CREATE DATABASE and IF NOT EXISTS. |
| PostgreSQL | Supports CREATE DATABASE; connect directly to the database after creation. |
| SQL Server | Supports CREATE DATABASE with additional file configuration options. |
| Oracle | Database creation is typically performed by administrators using Oracle-specific tools and options. |
| SQLite | A database is created automatically when a new database file is opened or created. |
â ī¸ Common Mistakes
- â Using a database name that already exists.
- â Forgetting to select the database before creating tables.
- â Using invalid characters or reserved keywords as the database name.
- â Creating a database without sufficient permissions.
Warning
â ī¸ Best Practices
Best Practice
đ Key Points to Remember
- đ CREATE DATABASE creates a new database.
- đ It is a Data Definition Language (DDL) statement.
- đ A database must exist before tables can be created.
- đ Database features and options vary across SQL systems.
- đ Appropriate permissions are required to create databases.
- đ A well-organized database improves maintainability and scalability.