Thursday, October 4, 2007

Drop database even it is in use

The following script will delete a database even if it is in use:


EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'MyDatabase'
GO
USE [master]
GO
ALTER DATABASE [MyDatabase] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE [MyDatabase] SET SINGLE_USER
GO
USE [master]
GO
DROP DATABASE [MyDatabase]
GO


Hope it helps.
http://www.IKOSoftware.com

1 comment:

Notebooks said...
This comment has been removed by a blog administrator.