Thursday, March 9, 2017

SQL DROP Database

The SQL DROP DATABASE command is used to drop an existing database in SQL schema. The DROP command will drop all the database object i.e. tables, views, procedures, etc. contained within the database.

To drop the database, the user should have the admin privilege for performing the drop action. After dropping the database, it will be removed from the list of databases. To get the list of databases, it can be retrieved using EXEC sp_databases;

Dropping a database deletes the selected database from SQL Server and also deletes the disk files on the physical drive used by the database. Dropping the database when it or any one of its files is offline does not delete the disk files. These files can be deleted manually using file explorer.


Syntax:

DROP DATABASE [DATEBASE_NAME];

DATEBASE_NAME is the name of the database to be dropped.


Example:

DROP DATABASE TekGrabs;



To drop a database, it must exist in the instance of the SQL server. If database to be dropped does not exist in the instance, the command will return the following error.



Caution:

The DROP statement cannot be rollback. Once the database is dropped, the information and database objects in the database will be lost. User should take a backup of the database before dropping to recover it later at any stage as required.


Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: