In a Database Management System (DBMS), a database is a structured collection of related data. Before storing tables and records, a database must first be created on the database server. The CREATE DATABASE command is used to create a new database where users can organize and store their data.
This command is commonly used by database administrators (DBAs) and developers when setting up a new application or project.
The CREATE DATABASE query is a Data Definition Language (DDL) command used to create a new database in the database server.
Once the database is created, users can add tables, insert records, and manage data within it.
CREATE DATABASE database_name;
When the CREATE DATABASE command is executed:
CREATE DATABASE student_db;
After executing this command, a new database named student_db will be created on the server.
You can verify the creation by running:
SHOW DATABASES;
Example Output:
| Database |
|---|
| information_schema |
| mysql |
| student_db |
IF NOT EXISTSSometimes a database may already exist. To prevent errors, MySQL provides the IF NOT EXISTS option.
CREATE DATABASE IF NOT EXISTS database_name;
CREATE DATABASE IF NOT EXISTS library_db;
If library_db already exists, the system will not create a duplicate database and no error will occur.
After creating a database, it must be selected before creating tables inside it.
USE student_db;
Now all tables and operations will be performed inside student_db.
CREATE DATABASE is a DDL command.IF NOT EXISTS clause prevents errors if the database already exists.USE database_name;.The CREATE DATABASE command is used to create a new database in a DBMS. It provides a storage structure where tables and data can be organized efficiently. This command is an important first step in setting up any database-driven application.