Do you remember when we delete any database from T-SQL as DROP DATABASE <DB Name>, sometimes we get error as can't delete database as it's currently is in use.
To fix this one way is to run sp_who command and then kill the session id used by the database and then run DROP DATABASE command.
There is one better way to do the same as below.
- USE MASTER
- GO
- ALTER DATABASE <DB Name> SET OFFLINE WITH ROLLBACK IMMEDIATE
- GO
- DROP DATABASE <DB Name>
- GO
