删除指定数据库的链接进程,用于分离数据库
时间:2021-07-01 10:21:17
帮助过:29人阅读
PROC [dbo].
[SYS_DB_KillConnections]
(
@dbname VARCHAR(
200)
)
AS
DECLARE @sql NVARCHAR(
500)
DECLARE @spid NVARCHAR(
20)
DECLARE #tb
CURSOR FOR
SELECT spid
=CAST(spid
AS VARCHAR(
20))
FROM master..sysprocesses
WHERE dbid
=DB_ID(
@dbname)
OPEN #tb
FETCH NEXT FROM #tb
INTO @spid
WHILE @@fetch_status = 0
BEGIN
EXEC(
‘kill ‘+@spid)
FETCH NEXT FROM #tb
INTO @spid
END
CLOSE #tb
DEALLOCATE #tb
GO
删除指定数据库的链接进程,用于分离数据库
标签:alt roc while next end div ast color HERE