- SQL Basics
- SQL Introduction
- SQL Syntax
- SQL Sample Database
- SQL SELECT
- SQL WHERE
- SQL ORDER BY
- SQL DISTINCT
- SQL LIMIT
- SQL FETCH
- SQL AND
- SQL OR
- SQL BETWEEN
- SQL IN
- SQL LIKE
- SQL IS NULL
- SQL Comparison Operators
- SQL Logical Operators
- SQL Alias
- SQL CASE
- Joins and Subqueries
- SQL INNER JOIN
- SQL LEFT JOIN
- SQL RIGHT JOIN
- SQL FULL OUTER JOIN
- SQL SELF JOIN
- SQL CROSS JOIN
- SQL Subquery
- SQL Correlated Subquery
- SQL UNION
- SQL INTERSECT
- SQL EXCEPT
- Aggregate Functions
- SQL AVG
- SQL COUNT
- SQL MAX
- SQL MIN
- SQL SUM
- SQL GROUP BY
- SQL HAVING
- SQL ROLLUP
- SQL CUBE
- SQL GROUPING SETS
- Database Management
- SQL CREATE DATABASE
- SQL ALTER DATABASE
- SQL DROP DATABASE
- SQL BACKUP DATABASE
- SQL SHOW DATABASES
- SQL SELECT DATABASE
- Table Management
- SQL CREATE TABLE
- SQL ALTER TABLE
- SQL ADD COLUMN
- SQL DROP COLUMN
- SQL DROP TABLE
- SQL TRUNCATE TABLE
- SQL SHOW TABLES
- SQL RENAME TABLE
- SQL Constraints
- SQL Primary Key
- SQL Foreign Key
- SQL UNIQUE Constraint
- SQL CHECK Constraint
- SQL NOT NULL Constraint
SQL DROP DATABASE
The DROP DATABASE
statement is used to permanently delete an existing database along with all its tables, views, and other objects.
Syntax of SQL DROP DATABASE
DROP DATABASE database_name;
- database_name: The name of the database to be deleted.
Key Features of SQL DROP DATABASE
- Completely removes a database and its contents.
- Requires administrative privileges.
- Cannot be undone once executed.
Example of SQL DROP DATABASE
DROP DATABASE SchoolDB;
Output:
The SchoolDB
database is deleted permanently.
Checking Available Databases
To see the list of existing databases before dropping one:
SHOW DATABASES;
Conditional Deletion
To prevent errors when dropping a non-existent database, use:
DROP DATABASE IF EXISTS SchoolDB;
Output:
Drops SchoolDB
only if it exists, avoiding errors.
Summary
DROP DATABASE
permanently deletes a database.- Use
IF EXISTS
to avoid errors. - Always check existing databases using
SHOW DATABASES
. - This operation cannot be undone, so proceed with caution.