What is DROP DATABASE?
The DROP DATABASE statement is used to permanently delete
an entire database. When a database is dropped, the database and the
objects stored inside it, such as tables and views, are removed.
Important: SQLite does not support the
DROP DATABASE statement. SQLite databases are stored as
database files, so deleting an SQLite database normally means deleting
its database file. The interactive examples below use SQLite-compatible
SQL and therefore demonstrate how to remove tables and database objects
safely within the SQLite editor.
Basic DROP DATABASE Syntax
In database systems that support it, the basic syntax is:
DROP DATABASE database_name;
This is valid for database systems that support
DROP DATABASE, but it will return an error if executed
directly in SQLite.
DROP DATABASE Example
For example, the following statement can be used in a database system
that supports the command to remove a database named
training_db.
DROP DATABASE training_db;
Note: Do not run this example in the SQLite editor
because SQLite does not implement the DROP DATABASE
statement.
DROP DATABASE IF EXISTS
Some database systems support IF EXISTS. It allows the
command to proceed without generating an error when the specified
database does not exist.
DROP DATABASE IF EXISTS training_db;
The exact syntax and behavior can vary between database management systems. This command is not supported by SQLite.
SQLite Alternative: DROP TABLE
Since SQLite does not have DROP DATABASE, you can remove
individual tables using DROP TABLE.
DROP TABLE IF EXISTS courses;
CREATE TABLE courses (
course_id INTEGER PRIMARY KEY,
course_name TEXT,
duration INTEGER
);
INSERT INTO courses VALUES
(1, 'SQL Fundamentals', 30),
(2, 'Web Development', 45),
(3, 'Data Analysis', 40);
SELECT *
FROM courses
ORDER BY course_id;
DROP TABLE courses;
The example first creates and displays the table and then removes it.
The final DROP TABLE statement is SQLite-compatible.
DROP Multiple SQLite Tables
If a SQLite database contains several tables, each table can be removed separately.
DROP TABLE IF EXISTS customers;
DROP TABLE IF EXISTS orders;
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY,
customer_name TEXT
);
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER,
amount REAL
);
INSERT INTO customers VALUES
(1, 'Aarav'),
(2, 'Meera');
INSERT INTO orders VALUES
(101, 1, 2500.00),
(102, 2, 1800.00);
SELECT
customers.customer_name,
orders.amount
FROM customers
JOIN orders
ON customers.customer_id = orders.customer_id
ORDER BY orders.order_id;
DROP TABLE orders;
DROP TABLE customers;
DROP TABLE IF EXISTS
SQLite supports DROP TABLE IF EXISTS. This is useful when
you want to remove a table without receiving an error if the table is
already absent.
DROP TABLE IF EXISTS temporary_data;
CREATE TABLE temporary_data (
id INTEGER,
value TEXT
);
INSERT INTO temporary_data VALUES
(1, 'Alpha'),
(2, 'Beta'),
(3, 'Gamma');
SELECT *
FROM temporary_data;
DROP TABLE IF EXISTS temporary_data;
Checking Tables Before Dropping
SQLite provides the sqlite_master table, which can be used
to inspect existing tables before removing them.
DROP TABLE IF EXISTS inventory;
CREATE TABLE inventory (
item_id INTEGER PRIMARY KEY,
item_name TEXT,
quantity INTEGER
);
SELECT
name,
type
FROM sqlite_master
WHERE type = 'table'
AND name = 'inventory';
DROP TABLE inventory;
DROP DATABASE vs DROP TABLE
| Statement | Purpose | SQLite Support |
|---|---|---|
| DROP DATABASE | Deletes an entire database | No |
| DROP TABLE | Deletes a table and its data | Yes |
| DROP VIEW | Deletes a view | Yes |
Database Systems Supporting DROP DATABASE
| Database System | DROP DATABASE | Typical Syntax |
|---|---|---|
| MySQL | Supported | DROP DATABASE database_name; |
| PostgreSQL | Supported | DROP DATABASE database_name; |
| SQL Server | Supported | DROP DATABASE database_name; |
| SQLite | Not supported | Delete the database file |
Important Points
DROP DATABASEpermanently removes a database in systems that support it.- Dropping a database can remove all of its tables, views, and stored data.
- SQLite does not support the
DROP DATABASEstatement. - In SQLite, individual tables can be removed using
DROP TABLE. - Use
IF EXISTSwhen supported to avoid errors for missing objects. - Always make sure important data is backed up before performing destructive operations.
Best Practices
- Verify the database name before dropping it.
- Back up important data before destructive operations.
- Use
IF EXISTSwhen appropriate. - Do not use DROP statements casually in production databases.
- Understand the difference between dropping a database and dropping a table.
- Remember that SQLite uses database files instead of server-managed databases.
The DROP DATABASE statement is a
powerful command used to permanently remove an entire database.
Because SQLite does not support this statement, SQLite users generally
remove individual objects with commands such as
DROP TABLE, while the database itself is represented by
a file.
🧪 Test Your SQL Code
Edit the SQL code on the left and click “Run Code” to see the result on the right.
Click “Run Code” to see the result here.