Chapter 3: Database Creation and Management

Think of a database as a big folder (or a filing cabinet) that contains many tables (like spreadsheets inside that folder). One server/computer can hold hundreds or thousands of these databases — each one completely separate from the others.

We’ll cover four main commands today:

  • CREATE DATABASE → Make a new database
  • DROP DATABASE → Delete a database (careful!)
  • USE / SELECT DATABASE → Switch to / choose which database you want to work in
  • SHOW DATABASES → See the list of all databases on your server

I’ll explain each one in detail, with real examples, warnings, and best practices — just like we’re sitting together in a Mumbai café and I’m showing you on my laptop.

1. CREATE DATABASE – Making a New Database

This is how you create a brand-new, empty database.

Basic Syntax:

SQL

Real-world example:

SQL

Important options you’ll often use:

SQL
  • CHARACTER SET utf8mb4 → Supports emojis, all Indian languages (Hindi, Marathi, Tamil, etc.), and special characters
  • COLLATE utf8mb4_unicode_ci → Case-insensitive sorting, perfect for most apps

Even better (full modern example):

SQL
  • IF NOT EXISTS → Super safe! If the database already exists, it won’t throw an error — just skips creation.

Pro Tip: Always use utf8mb4 in 2026 — it’s the modern standard that handles everything correctly.

2. SHOW DATABASES – Listing All Databases

Once you have some databases, you’ll want to see what’s there.

Syntax:

SQL

Example output (what you might see):

text
  • information_schema, mysql, performance_schema, sys → These are system databases that come with every MySQL/PostgreSQL server. Never touch or delete them!

Tip: You can filter the list:

SQL

3. USE / SELECT DATABASE – Switching to a Database

After creating a database, you need to tell the system “Hey, I want to work inside THIS database now.”

Syntax (most common):

SQL

Alternative (works in some tools):

SQL

Example session:

SQL

Important note:

  • In MySQL, MariaDB, SQL Server → You use USE database_name;
  • In PostgreSQL → You use \c database_name in psql, or SET search_path TO database_name; — but most tools let you do USE too.
  • In SQLite → There is only one database file, so no USE needed.

4. DROP DATABASE – Deleting a Database (Be Very Careful!)

This command permanently deletes the entire database and everything inside it — tables, data, indexes, everything. No recycle bin!

Syntax:

SQL

Safe version:

SQL

Example:

SQL

Big Warning (listen carefully!):

  • There is no UNDO for DROP DATABASE.
  • In production, always double-check the name.
  • Many teams disable DROP DATABASE permission for regular users in production servers — only DBAs can do it.
  • Before dropping, people often do:
    SQL

Real-life story: A junior developer once typed DROP DATABASE production; instead of DROP DATABASE test_production; in a live server… 3 hours of panic and restore from backup. Lesson: Always triple-check!

Full Example Workflow (copy-paste this!)

SQL

Best Practices Summary (2026 Style)

Command Best Practice Recommendation
CREATE DATABASE Always use IF NOT EXISTS + utf8mb4_unicode_ci
SHOW DATABASES Use LIKE ‘prefix%’ to filter when you have many DBs
USE Run it at the start of every new session/script
DROP DATABASE Never run it without IF EXISTS and confirmation
Naming Use lowercase + underscores: ecommerce_2026, hr_system
Security Don’t give DROP privilege to app users — only to admins

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *