Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #107

CREATE DATABASE in SQL

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 USE vs FROM
  • 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.

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →