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.
- Handled using SQL commands
- Part of DDL
- Affect database structure
2. CREATE DATABASE
The CREATE DATABASE command is used to create a new database.
CREATE DATABASE college_db;
- Creates an empty database
- Database name must be unique
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;
- Selects active database
- Required before creating tables
5. DROP DATABASE
The DROP DATABASE command deletes a database permanently.
DROP DATABASE college_db;
- Deletes database completely
- All tables and data are lost
- Cannot be undone
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
- Database name should follow naming rules
- DROP DATABASE is irreversible
- Always use IF EXISTS for safety
Practice Questions
- What is CREATE DATABASE?
- Write syntax for DROP DATABASE.
- Why USE command is required?
- What is the use of IF EXISTS?
- 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