Every query in this course so far has run against Beacon Robotics' existing employees, departments, projects, and project_assignments tables. This module steps back one level: how a database, and the tables inside it, actually get created in the first place, starting with the database itself.
Learning Objectives
- Create a new database with CREATE DATABASE.
- Explain why SQLite has no CREATE DATABASE statement at all.
- Recognize Oracle's database concept as meaningfully different from the other five.
Basic CREATE DATABASE
This creates a new, completely empty database, no tables yet, just a named container ready to hold them. Connecting to it (USE beacon_robotics; on MySQL/MariaDB/SQL Server, or specifying it at connection time on PostgreSQL) comes before any CREATE TABLE statement runs inside it.
CREATE DATABASE beacon_robotics;
IF NOT EXISTS
Without this, running CREATE DATABASE against a name that already exists errors. IF NOT EXISTS makes the statement safely re-runnable, creating the database only if it isn't already there, doing nothing (rather than erroring) otherwise. SQL Server doesn't support this exact clause, a conditional check against sys.databases is used there instead.
CREATE DATABASE IF NOT EXISTS beacon_robotics;
SQLite and Oracle Are Different
| Database | How a New Database Is Created |
|---|---|
| MySQL / MariaDB / PostgreSQL / SQL Server | CREATE DATABASE name; |
| SQLite | No statement at all, a database is just a file, created automatically the moment a program connects to a filename that doesn't exist yet |
| Oracle | Not a routine statement, creating a new Oracle database (or pluggable database) is a heavyweight, DBA-level operation, well beyond this course's scope |
SQLite has no server process and no CREATE DATABASE statement, a SQLite database is literally one file on disk. Opening a connection to beacon_robotics.db, a filename that doesn't exist yet, creates it automatically. Oracle, on the other end of the spectrum, treats a database as a substantial, typically pre-provisioned piece of infrastructure, day-to-day development usually works inside an existing database/schema rather than creating new ones.
Try It Yourself
Write a safely re-runnable statement that creates a database named beacon_robotics_staging on MySQL.
CREATE DATABASE IF NOT EXISTS beacon_robotics_staging;
Frequently Asked Questions
Can a database's character set or collation be set at creation time?
Yes, on MySQL/MariaDB/PostgreSQL/SQL Server, optional clauses like CHARACTER SET and COLLATE can be added to CREATE DATABASE. The defaults are usually fine for learning, this becomes relevant for real production systems handling multiple languages or needing specific sort behavior.
Does creating a database require special permissions?
Yes, on every database that supports the statement, creating (and dropping) databases typically requires elevated privileges, not something a regular application-level database user is normally granted.
Common Beginner Mistakes
Looking for a CREATE DATABASE statement on SQLite
It doesn't exist, there's nothing to run, connecting to a new filename is the entire "creation" step. Searching for equivalent syntax on SQLite is a common, understandable, but ultimately pointless search.
Running CREATE DATABASE without IF NOT EXISTS in a script that might run more than once
The second run errors on a name that already exists. IF NOT EXISTS (where supported) makes setup scripts safely re-runnable.
Best Practices
- Use IF NOT EXISTS in setup scripts meant to be run more than once.
- Pick clear, descriptive database names, the same naming-convention principle from Module 1 applies at the database level too.
- Don't search for CREATE DATABASE syntax on SQLite, a new filename is the entire mechanism.
Interview Questions
Why doesn't SQLite have a CREATE DATABASE statement?
SQLite is a serverless, file-based database engine, a "database" is just a single file on disk. Opening a connection to a filename that doesn't already exist creates it automatically, there's no separate creation step or statement needed.
What does CREATE DATABASE IF NOT EXISTS accomplish that plain CREATE DATABASE doesn't?
It makes the statement safely re-runnable: if the database already exists, it does nothing instead of raising an error, useful in setup or migration scripts that might execute more than once.
Summary
CREATE DATABASE name; creates a new, empty database on MySQL, MariaDB, PostgreSQL, and SQL Server, with IF NOT EXISTS available on most of them for safe re-runs. SQLite has no such statement, a database is simply a file; Oracle treats database creation as a heavyweight, infrequent operation outside this course's everyday scope.
What's Next?
DROP DATABASE next, permanently removing one, along with everything inside it.
Ready to Practice SQL?
Write and run real SQL queries online, right in your browser, no install or signup required. Pick a playground based on which database you want to practice on.
Both open a third-party SQL playground in a new tab. External site terms and privacy policy apply.