"无法删除数据库,因为该数据库当前正在使用"问题解决
时间:2021-07-01 10:21:17
帮助过:75人阅读
MASTER
GO
DECLARE @dbname SYSNAME
SET @dbname = ‘databasename‘ --这个是要删除的数据库库名
DECLARE @s NVARCHAR(
1000)
DECLARE tb
CURSOR LOCAL
FOR
SELECT s
= ‘kill ‘ + CAST(spid
AS VARCHAR)
FROM MASTER..sysprocesses
WHERE dbid
= DB_ID(
@dbname)
OPEN tb
FETCH NEXT FROM tb
INTO @s
WHILE @@fetch_status = 0
BEGIN
EXEC (
@s)
FETCH NEXT FROM tb
INTO @s
END
CLOSE tb
DEALLOCATE tb
EXEC (
‘drop database [‘ + @dbname + ‘]‘)
"无法删除数据库,因为该数据库当前正在使用"问题解决
标签:varchar into style nvarchar 数据库 dbid status base spro