SQL DROP DATABASE Statement

The DROP DATABASE Statement in SQL is used to drop or delete a database. Dropping of the database will drop all database objects like tables, views, procedures etc. inside it. The user should have admin privileges for deleting a database.

Once you execute DROP statement it cannot be rolled back.

DROP DATABASE Statement

Syntax:

  DROP DATABASE [IF EXISTS] database_name;
In the above query, database_name is the name of the database to be dropped. All major SQL's like MySQL, Postgresql follow same syntax for dropping a database.

DROP DATABASE Example:

If you want to drop database named 'Admissions', the statement would be like
  DROP DATABASE Admissions ;
The IF EXISTS part in square brackets is optional, if specified it simply means if the database exists then drop it. If the database doesn't exists, this sql statement will not given you error like "Database don't exist".
  DROP DATABASE IF EXISTS Admissions ;
Remember only database name is case sensitive all other parts in above sql query are not case sensitive.

DROP STATEMENT CAUTION

To drop a database you need to have drop privileges on that database. Use this statement very carefully because once you dropped the database you cannot recover it. Only way to avoid loss of data is to keep a backup of corresponding database.

Comments