Friday, March 6, 2020

cannot drop database because it is currently in use.

-- Script para matar el proceso que no te permite eliminar la base de datos

DECLARE @DatabaseName nvarchar(50)
SET @DatabaseName = N'DatabaseName'

DECLARE @SQL varchar(max)

SELECT @SQL = COALESCE(@SQL,'') + 'Kill ' + Convert(varchar, SPId) + ';'
FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId

--Use this to see results
SELECT @SQL
--Uncomment this to run it
EXEC(@SQL)

drop database DatabaseName

No comments:

Post a Comment