R
Rishtaara
SQL: Zero to Data Analyst
Lesson 17 of 30Article13 min

CREATE DATABASE, DROP & BACKUP

CREATE DATABASE makes a new empty container for tables. You then USE or connect to that database before creating tables.

CREATE DATABASE — start a new database

CREATE DATABASE makes a new empty container for tables. You then USE or connect to that database before creating tables.

Real-life example: CREATE DATABASE is opening a new filing cabinet labeled 'Springfield High 2026' — empty until you add folders (tables).

Create and switch to a school database
CREATE DATABASE school_db;

-- MySQL
USE school_db;

-- PostgreSQL: connect with \c school_db in psql

DROP DATABASE — delete entire database

DROP DATABASE permanently removes the database and all its tables. There is no undo — always backup first.

Real-life example: DROP DATABASE is shredding the whole cabinet — every folder inside goes with it.

On shared servers you rarely have permission to DROP DATABASE. Practice on local SQLite or a sandbox account.
Drop only when you are sure
-- Danger: removes everything in school_db
DROP DATABASE school_db;

BACKUP DATABASE — save a copy

Backups protect against mistakes and hardware failure. SQL Server uses BACKUP DATABASE. MySQL often uses mysqldump from the shell. PostgreSQL uses pg_dump.

Real-life example: BACKUP is photocopying the entire register before exam week — if ink spills, you restore from the copy.

SQL Server backup example
BACKUP DATABASE school_db
TO DISK = 'C:\Backups\school_db.bak';
Typical shell commands (run outside SQL)
-- MySQL (terminal)
-- mysqldump -u root -p school_db > school_db_backup.sql

-- PostgreSQL (terminal)
-- pg_dump school_db > school_db_backup.sql

-- Restore MySQL
-- mysql -u root -p school_db < school_db_backup.sql