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

SQL DROP DATABASE

Last Updated : 10 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

SQL DROP DATABASE statement deletes an existing database from the system, and once deleted, users can not retrieve that database.

The DROP DATABASE command in SQL deletes the database along with its data, like tables, views, indexes, constraints, and properties like permissions and schemas.

Syntax

SQL DROP TABLE syntax is:

DROP DATABASE database_name;

SQL DROP DATABASE Examples

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: Make sure you have taken proper backup of the database before you delete 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 dropped

Previous Article
Next Article

Similar Reads

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
CREATE and DROP INDEX Statement in SQL
The CREATE INDEX statement will create indexes in tables. Indexes are used for data procurement from the databases faster. The users cannot see the indexes, they are running in the background of queries, used to speed up searches/queries. Create an index on a table : Syntax: CREATE INDEX indexname ON tablename (columnname1, columnname2, ...); Creat
2 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 DROP TABLE
SQL DROP TABLE statement deletes data and structure of a table from the database. DROP TABLE in SQLDROP TABLE in SQL means that all of the table's data, structure, constraints, permissions, etc. will be removed from the database. DROP TABLE command is irreversible, so once a DROP TABLE command is executed for a table, all information about that tab
2 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 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
Backup Database in MS SQL Server
Prerequisite – Create database in MS SQL Server To Create a Full Database Backup, the below methods could be used - SQL Server Management Studio. Transact-SQL. Restriction : Backups created on a newer version of SQL Server cannot be restored in previous versions of SQL Server. Facts to know : When the database size increases, full database backups
3 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
Oracle DataBase - Grant Privileges to a User in SQL Command Line
As we create a new user in the Oracle database, we first need to grant it the required privileges. After that only we can use that user to perform any task, provided that task comes under the role of privileges provided to it. This is illustrated below. For this article, we will be using the SQL Command-Line. Step 1: Open the SQL Command Line by ty
2 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
SQL Query to Add Ranking Positions of Rows in a Database With RANK()
In this article, we will discuss the overview of SQL function RANK and then our main focus will be on Add Ranking Positions of Rows in a Database With RANK() in SQL. Let's discuss it one by one. Overview :Generally, when max/min commands are executed, a single row is displayed as output. RANK() is an SQL function introduced in order to rank the row
2 min read
SQL Query to Add an Agent Parameter in a Database
In this article, we will learn how we add an extra or a new parameter after a table is created using ALTER command in Microsoft SQL Server in detail step-by-step: Step 1: Creating database sales by using the following SQL query: CREATE DATABASE sales; Step 2: Using the database sales by using the following SQL query: USE sales; Step 3: Creating a t
2 min read
SQL Query to Get First and Last Day of a Week in a Database
An SQL query is a single line statement of a Program written in a particular language to perform a specific task. A query consists of some pre-defined functions in SQL like SELECT, CREATE, etc. So, in this article, we will learn about SQL query to get the first and last day of a week in a database. So let's create a database first to do our task, h
2 min read
How to Restore SQL Server Database From Backup?
A Database is defined as a structured form of data that is stored database a computer or data in an organized manner and can be accessed in various ways. It is also the collection of schemas, tables, queries, views, etc. Databases help us with easily storing, accessing, and manipulating data held on a computer. The Database Management System allows
2 min read
Set Database From Single User Mode to Multi User in SQL
A single-user mode specifies that only one user at a time can access the database. If you set the database to single-user mode then all other connections will be closed without warning. If you get disconnected after setting the database into single-user mode, a different user can connect to database, but only one user. Where as in multiple-user mod
4 min read
Microsoft Azure - TDE is Enabled in Azure SQL Database
Pre-requisite: Azure VM Transparent Data EncryptionBy encrypting data at rest, transparent data encryption (TDE) protects Azure SQL Database, Azure SQL Managed Instance, and Azure Synapse Analytics against the threat of unauthorized offline actions. Without requiring changes to the system, it enables real-time encryption and decryption of the datab
3 min read
Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
In this article, we will be learning about how to do basic database operations using JDBC (Java Database Connectivity) API in Java programming language. These basic operations are INSERT, SELECT, UPDATE, and DELETE statements in SQL language. Although the target database system is Oracle Database, the same techniques can be applied to other databas
6 min read
Article Tags :
three90RightbarBannerImg