1 USE master 2 go 3 4 IF EXISTS ( SELECT * 5 FROM dbo.sysobjects 6 WHERE id = OBJECT_ID(N‘[dbo].[P_KillConnections]‘) 7 AND OBJECTPROPERTY(id, N‘IsProcedure‘) = 1 ) 8 DROP PROCEDURE [dbo].[P_KillConnections] 9 GO 10 11 CREATE PROC P_KillConnections @dbname VARCHAR(200) 12 AS 13 DECLARE @sql NVARCHAR(500) 14 DECLARE @spid NVARCHAR(20) 15 16 DECLARE #tb CURSOR FOR 17 SELECT spid=CAST(spid AS VARCHAR(20)) FROM master..sysprocesses WHERE dbid=DB_ID(@dbname) 18 OPEN #tb 19 FETCH NEXT FROM #tb INTO @spid 20 WHILE @@fetch_status = 0 21 BEGIN 22 EXEC(‘kill ‘+@spid) 23 FETCH NEXT FROM #tb INTO @spid 24 END 25 CLOSE #tb 26 DEALLOCATE #tb 27 go 28 29 30 --修改一下 31 EXEC P_KillConnections ‘修改成自己的数据库‘
时间: 2024-11-07 12:07:44