The Wayback Machine - https://web.archive.org/web/20241006155913/https://www.geeksforgeeks.org/sql-drop-database/
Open In App

SQL DROP DATABASE

Last Updated : 18 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

SQL DROP DATABASE statement is a powerful command used to permanently delete an existing database from a database management system (DBMS).

In this article, We will learn about SQL DROP DATABASE in detail by understanding various examples in detail.

SQL DROP DATABASE

  • SQL DROP DATABASE statement is used to delete an existing database from the database management system (DBMS).
  • This operation permanently removes the database and all its associated data, including tables, views, stored procedures, and any other objects contained within the database.

Syntax

SQL DROP TABLE syntax is:

DROP DATABASE database_name;

Examples of SQL DROP DATABASE

Let’s look at some examples of the DROP DATABASE statement in SQL.

First, let’s create a database on which we will run the query.

CREATE DATABASE GeeksForGeeks;

Now if we look at the list of databases in our system, we can find the “GeeksforGeeks” database.

Query:

SHOW DATABASES;
ShowDB

List of Databases

Now we will use the DROP DATABASE command, to delete the database ‘GeeksforGeeks’.

Query

DROP DATABASE GeeksForGeeks;

Output

drop database output

DROP DATABASE

Verify DROP DATABASE Statement

After the database has been deleted/dropped successfully we will now verify that whether the database exist in the system or not. So, we will once again use the SHOW DATABASES command and verify that the GeeksForGeeks database has been deleted or not.

Query

SHOW DATABASES;

Output

ShowDB2

Deleted Data

SQL DROP DATABASE IF EXISTS

To avoid any error while running the DROP DATABASE command use the IF EXISTS clause, which will delete the database only if it exists in the system.

Syntax

DROP DATABASE IF EXISTS Database_Name;

Important Points About SQL DROP DATABASE Statement

  • Deleting a Database: Deleting a database is a permanent action and will result in the loss of all information stored in the database.
  • Backup: Its always been a good practice to take proper backup of the database before performing any delete operation on it.
  • Privileges: Make sure you have the necessary privilege to delete the database. Usually an admin can delete the database.
  • Database State: A database can be dropped regardless of its state: offline, read-only, suspect, and so on.
  • Database Snapshots: Dropping a database snapshot deletes the database snapshot from an instance of SQL Server and deletes the physical NTFS File System sparse files used by the snapshot.
  • Replication: To drop a database published for transactional replication, or published or subscribed to merge replication, you must first remove replication from the database.
  • System Databases: System databases cannot be directly dropped or edited by the user.

Conclusion

The DROP DATABASE statement is essential for managing databases within a DBMS, allowing administrators to completely remove databases that are no longer needed. While it is a straightforward command, it is crucial to ensure that backups are taken and that the appropriate privileges are in place before executing it.

What is DROP DATABASE in MySQL?

The DROP DATABASE statement in MySQL is used to permanently delete an existing database along with all of its tables, data, and associated objects. This action is irreversible and removes the entire database structure and content.

How do I drop a database from SQL?

To drop a database using SQL, you use the DROP DATABASE statement followed by the name of the database you want to delete. This command will permanently remove the specified database and all of its contents.

What is the difference between DROP DATABASE and DELETE DATABASE?

  • DROP DATABASE: This statement completely removes a database, including all tables, data, and database schema. It is irreversible and deletes everything associated with the database.
  • DELETE DATABASE: This is not a valid SQL command. To delete data within a database but keep the database structure intact, you would use the DELETE or TRUNCATE statements on individual tables. These commands remove data from the tables but do not drop the database itself.

Previous Article
Next Article

Similar Reads

MySQL Drop Database
In Database Management Systems managing databases involves not only creating and modifying the data but also removing the databases when they are no longer needed and freeing the space occupied by them. MySQL offers a feature called DROP DATABASE, allowing users to delete databases. In this article, We will see How to Drop Databases in MySQL, vario
3 min read
MariaDB Drop Database
MariaDB, an open-source relational database management system widely used by users, enables them to manage their databases efficiently. MariaDB Offers fast data processing and scalability. MariaDB Stores data in tables with structured relationships between them. In this article, We will learn about the DROP DATABASE command, how to write its syntax
4 min read
MongoDB Drop Database
In MongoDB, dropping a database means deleting the entire database along with all its associated collections (tables in relational databases). This action permanently removes all data stored within that database. It's crucial to exercise caution when dropping a database as this cannot be undone. In this article, we'll delve into the concept of drop
3 min read
Create a drop-down list that options fetched from a MySQL database in PHP
In many scenarios, we may need to create a dropdown input that can display all the options consistent with the current state of the database. This form of input is used many times in real life and the following examples may help to understand the same. A set of students who have unique registration numbers.A set of branch names and their branch ids
4 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
Configure SQL Jobs in SQL Server using T-SQL
In this article, we will learn how to configure SQL jobs in SQL Server using T-SQL. Also, we will discuss the parameters of SQL jobs in SQL Server using T-SQL in detail. Let's discuss it one by one. Introduction :SQL Server Agent is a component used for database task automation. For Example, If we need to perform index maintenance on Production ser
7 min read
SQL vs NO SQL vs NEW SQL
SQL stands for Structured Query Language. Which is based on relational algebra and schema is fixed in this which means data is stored in the form of columns and tables. SQL follows ACID properties which means Atomicity, Consistency, Isolation, and Durability are maintained. There are three types of languages present in SQL : Data Definition Languag
2 min read
Drop login in SQL Server
The DROP LOGIN statement could be used to delete an user or login that used to connect to a SQL Server instance. Syntax - DROP LOGIN loginname; GO Permissions : The user which is deleting the login must have ALTER ANY LOGIN permission on the server. Note - A login which is currently logged into SQL Server cannot be dropped. If you try to drop login
1 min read
DROP SCHEMA in SQL Server
The DROP SCHEMA statement could be used to delete a schema from a database. SQL Server have some built-in schema, for example : dbo, guest, sys, and INFORMATION_SCHEMA which cannot be deleted. Syntax : DROP SCHEMA [IF EXISTS] schema_name; Note : Delete all objects from the schema before dropping the schema. If the schema have any object in it, the
1 min read
SQL Query to Drop Unique Key Constraints Using ALTER Command
Here, we see how to drop unique constraints using alter command. ALTER is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table. Syntax : ALTER TABLE table_name DROP CONSTRAINT unique_constraint; For instance, consider the below table 'Employee'. Create a Table: C
2 min read
SQL DROP CONSTRAINT
In SQL, the DROP CONSTRAINT command is used to remove constraints from the columns of a table. Constraints are used to limit a column on what values it can take. We add constraints to our columns while we are creating the structure of tables in SQL and when we are actually inserting values in those tables sometimes we find that there is no further
3 min read
SQL DROP COLUMN
The Data Definition Language (DDL) command DROP COLUMN is used in SQL (Structured Query Language). The structure of database objects like tables can be defined, altered, or deleted using DDL statements in SQL. A column can be removed from a database table using the DROP COLUMN command. The table is altered permanently by this command. There is no g
3 min read
SQL Server DROP TABLE
In SQL Server, the DROP TABLE statement is used to remove or delete permanently from the database. In SQL Server after performing the DROP Operation we cannot revoke the table or database again, because it is an irreversible action. The Drop Operation is different from the DELETE Command, In the DELETE command we can revoke the database or table af
3 min read
SQL Server ALTER TABLE DROP COLUMN
In SQL Server, there could be some situations when we may have to delete or drop a column from a table. Sometimes the column in a table was created wrongly or maybe it is no longer required and has become obsolete. So, to drop a column from a table, the ALTER TABLE, DROP COLUMN SQL query is used. In this article, we will discuss how to drop a colum
4 min read
SQL Server DELETE and DROP TABLE Commands
In SQL Server, managing data involves not only inserting and updating records but also removing them when they're no longer needed. Two important commands for data removal are DELETE and DROP TABLE. These commands play crucial roles in maintaining database integrity and managing database structures. In this article, we'll learn about the DELETE and
4 min read
PL/SQL DROP VIEW
Views serve as an important tool for simplifying complex queries, enhancing data security, and streamlining database management. They provide a virtual layer that presents data from underlying tables in a structured format. However, views like other database objects need to be managed effectively to maintain data integrity and optimize performance
3 min read
SQL DROP INDEX Statement
The SQL DROP INDEX statement removes an existing Index from a database table. SQL DROP INDEXThe SQL DROP INDEX Command is used to remove an index from the table. Indexes occupy space, which can cause extra time consumption on table modification operations. Benefits of Using DROP INDEX:Removing unused indexes can improve INSERT, UPDATE, and DELETE o
3 min read
DROP and TRUNCATE in SQL
DROP and TRUNCATE in SQL remove data from the table. The main difference between DROP and TRUNCATE commands in SQL is that DROP removes the table or database completely, while TRUNCATE only removes the data, preserving the table structure. Let's understand both these SQL commands in detail below: What is DROP Command?DROP command in SQL is used to
4 min read
Create, Alter and Drop schema in MS SQL Server
Schema management in MS SQL Server involves creating, altering, and dropping database schema elements such as tables, views, stored procedures, and indexes. It ensures that the database structure is optimized for data storage and retrieval. In this article, we will be discussing schema and how to create, alter, and drop the schema. What is Schema?A
4 min read
SQL Query to Drop Foreign Key Constraint Using ALTER Command
A foreign key is included in the structure of a table, to connect multiple tables by referring to the primary key of another table. Sometimes, you might want to remove the primary key constraint from a table for performance issues or other requirements. A foreign key constraint can be removed from a table using the ALTER TABLE command and DROP CONS
3 min read
Difference between DROP and TRUNCATE in SQL
In SQL, the DROP and TRUNCATE commands are used to remove data, but they operate differently. DROP deletes an entire table and its structure, while TRUNCATE removing only the table data. Understanding their differences is important for effective database management. In this article, We will learn about the difference between DROP and TRUNCATE in SQ
3 min read
SQL DROP TABLE
The DROP TABLE command in SQL is a powerful and essential tool used to permanently delete a table from a database, along with all of its data, structure, and associated constraints such as indexes, triggers, and permissions. When executed, this command removes the table and all its contents, making it unrecoverable unless backed up. In this article
3 min read
CREATE and DROP INDEX Statement in SQL
The CREATE INDEX statement in SQL is a powerful tool used to enhance the efficiency of data retrieval operations by creating indexes on one or more columns of a table. Indexes are crucial database objects that significantly speed up query performance, especially when dealing with large datasets. In this article, We will learn about How to CREATE an
4 min read
PL/SQL Drop Index
In PL/SQL an index is a database object that improves the speed of the data retrieval operations on the table. However, there are situations where we might want to remove an index either to optimize performance or to retrieve disk space. In this article, we will provide a comprehensive guide on how to use the DROP INDEX statement in PL/SQL along wi
4 min read
Database Sharding Pattern for Scaling Microservices Database Architecture
Database sharding is an architectural technique that divides a large database into smaller and more manageable sections called shards. Each shard operates as an independent database that stores a subset of the overall data. Traditional monolithic database designs face many challenges to keep up with rapidly growing data volumes and the demands for
5 min read
SQL Trigger | Book Management Database
Prerequisite - SQL Trigger | Student Database For example, given Library Book Management database schema with Student database schema. In these databases, if any student borrows a book from library then the count of that specified book should be decremented. To do so, Suppose the schema with some data, mysql> select * from book_det; +-----+-----
2 min read
Strategies For Migrating From SQL to NoSQL Database
Migrating from a SQL database to a NoSQL database can be a complex process, but there are several strategies that can be used to make the transition smoother. Here are some common strategies for migrating from SQL to NoSQL: Analyze the current SQL schema and data model: Before starting the migration, it's important to analyze the current SQL schema
7 min read
SQL queries on FILM Database
Consider the following tables in Film Database: ARTIST (Art_id, Art_Name, Art_Gender) PRODUCER (Prod_id, Prod_Name, Prod_Phone) FILMS (Film_id, Film_Title, Film_Year, Film_Lang, Prod_id) CASTING (Art_id, Film_id, Part) REVIEW (Film_id, Stars) The data content of these five tables are shown below: SELECT * FROM ARTIST;Art_idArt_NameArt_Gender101AMIT
3 min read
Delete Database in MS SQL Server
Prerequisite – Introduction of MS SQL Server and Create Database in MS SQL Server System databases can't be deleted, only user databases could be deleted. Data and log files will automatically be deleted from disk with database deletion. To delete a database, the below methods could be used – SQL Server Management Studio. Transact-SQL. These are ex
1 min read
SQL Query to Set First Day of the Week in a Database
In this article, we are going to write a SQL script to Set the first day of the week in a Database. Below is the implementation for the same. You should have MSSQL in your server. Query in SQL - A query is a request for data or information from a database table or combination of tables. This data can be used for various purposes like Training a mod
2 min read
Article Tags :