Notes

`CREATE DATABASE` Query in DBMS (MySQL) [ English ]

< Prev Next >

Introduction

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.

Definition

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.


Syntax

CREATE DATABASE database_name;

How It Works

When the CREATE DATABASE command is executed:

  1. The DBMS creates a new database container on the server.
  2. It allocates storage space for storing tables and other objects.
  3. The database name is added to the system catalog (metadata).
  4. The database becomes available for use.

Example

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

Using IF NOT EXISTS

Sometimes a database may already exist. To prevent errors, MySQL provides the IF NOT EXISTS option.

Syntax

CREATE DATABASE IF NOT EXISTS database_name;

Example

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.

Selecting the Created Database

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.

Key Points

Summary

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.

< Prev Next >