No Edge Software
  • Search results
No Edge Software

Drop Database

If you’re working locally, building a new app from scratch, you might be in a position where you want to wipe the database and start clean - but SQL Server may block you if you’ve got any open connections or any other issues blocking you.

This should set you as the only user of the database, which will clear the way for dropping it without ever getting an error:

use master;
go
if exists (select 1 from sys.databases where name = 'SomeDatabase')
begin
    alter database SomeDatabase set single_user with rollback immediate;
    drop database SomeDatabase;
end;
go

Author

Joe Enos