When ever we are droping or deleting the databse if it is used by other users. Sql server displays the following error message.
"cannot drop database "Database_Name" because it is currently in use"
To avoid this error message and close all the existing connections and drop immedeiately you need to use the following syntax.
Change theDatabase_Name with your Database name to drop.
IFEXISTS(SELECT name FROMsys.databasesWHERE name =N'Database_Name') BEGIN PRINT'DROP DATABASE [Database_Name']' ALTERDATABASE [Database_Name'] SETSINGLE_USERWITHROLLBACKIMMEDIATE DROPDATABASE [Database_Name'] END
GO