Introduction: Drop Database statement using SQL server
DROP database in SQL to remove an existing database from a SQL Server. The DROP DATABASE statement allows you to delete one or more databases from SQL Server.
Drop Database statement is fast?
Yes, it is fast. However, its also depends on how big is your database. its also happened that it will hanged sometime because the same database which you are trying to drop is used by another query. So be careful while dropping any database to make sure there is no usage of that database.
Below are Syntax
Syntax: For Deleting one database
DROP DATABASE [ IF EXISTS ]
database_name;
Syntax: For Deleting More then one database
DROP DATABASE [ IF EXISTS ]
database_name1,
database_name2
database_name3 ;
Important to know two things about Drop Database statement
- DROP DATABASE statement deletes the database and the tables within that database. Always keep backup of database so that you can retain that.
- You cannot drop the database that is currently being used.
Example #1: Drop test database with SQL Command
In our previous Create Database tutorial, we have created the Test_database to explain you how we can create database, now we have dropped the same database using DROP DATABASE statement in below example
DROP DATABASE IF EXISTS Test_database;
It will permanently delete the database. You will get error while drop database command, it means the same database is in used by another query.
Example #2: DELETE DATABASE Manually as well
- In your SQL Server Management Studio, Open the Database folder
- Right clicked on database which you ant to delete in this case we will right click on “test_database”
- then click on Delete option
You learn in this tutorial both way of dropping database.