Create & Drop Database

Database operations are SQL commands used to create, select, and remove databases. These commands come under DDL (Data Definition Language).

1. What are Database Operations?

Database operations allow users to manage databases at a high level. They include creating new databases, selecting databases, and deleting databases.

2. CREATE DATABASE

The CREATE DATABASE command is used to create a new database.

CREATE DATABASE college_db;

3. SHOW DATABASES

The SHOW DATABASES command displays all available databases.

SHOW DATABASES;

4. USE DATABASE

The USE command selects a database for performing operations.

USE college_db;

5. DROP DATABASE

The DROP DATABASE command deletes a database permanently.

DROP DATABASE college_db;

6. IF EXISTS / IF NOT EXISTS

These keywords prevent errors while creating or deleting databases.

CREATE DATABASE IF NOT EXISTS school_db;

DROP DATABASE IF EXISTS school_db;

7. CREATE vs DROP Database

Command          Purpose
---------------  --------------------------------
CREATE DATABASE  Creates a new database
DROP DATABASE    Deletes an existing database
USE              Selects database for use
SHOW DATABASES   Displays all databases

8. Important Points

Practice Questions

  1. What is CREATE DATABASE?
  2. Write syntax for DROP DATABASE.
  3. Why USE command is required?
  4. What is the use of IF EXISTS?
  5. Differentiate CREATE and DROP DATABASE.

Practice Task

Write SQL commands to: ✔ Create a database named library_db ✔ Display all databases ✔ Select library_db ✔ Delete library_db safely