The CREATE DATABASE statement creates a new, empty database — a container you'll then fill with tables.
Syntax
CREATE DATABASE database_name;
Example
CREATE DATABASE coding_now_academy;
To start using it in most tools:
USE coding_now_academy;
To see what already exists:
SHOW DATABASES; -- MySQL
\l -- PostgreSQL (psql shortcut)
Avoiding Errors on Re-Run
CREATE DATABASE IF NOT EXISTS coding_now_academy;
Without IF NOT EXISTS, re-running the statement on a database that already exists throws an error. This matters in setup scripts you might run more than once.
Dialect Note
PostgreSQL doesn't support IF NOT EXISTS for CREATE DATABASE the same way MySQL does — you typically check with SELECT 1 FROM pg_database WHERE datname = '...' first, or just handle the error in your script. SQL Server uses the same core CREATE DATABASE database_name; syntax as MySQL.
Common Mistakes
- Confusing a database name with a table name when writing
USEvsFROM - Creating a new database for every small project instead of using separate schemas/tables inside one — usually unnecessary overhead
Interview Relevance
Rarely tested in isolation, but interviewers expect you to know it's the first real step before CREATE TABLE — some candidates jump straight to tables and get asked "where does this table live?"
Practice Question
Write a statement that creates a database called library_system only if it doesn't already exist.