用于asp.net还原与恢复SqlServer数据库的KillSpid存储过程
代码
1 CREATE PROCEDURE KillSpid(@dbName varchar(20))
2 AS
3 BEGIN
4 DECLARE @sql nvarchar(500)
5 DECLARE @spid int
6
7 SET @sql='DECLARE getspid CURSOR FOR SELECT spid FROM sysprocesses WHERE dbid=db_id('''+@dbName+''')'
8 EXEC (@sql)
9 OPEN getspid
10 FETCH next FROM getspid INTO @spid
11 WHILE @@fetch_status<>-1
12 BEGIN
13 EXEC('kill '+@spid)
14 FETCH next FROM getspid INTO @spid
15 END
16 CLOSE getspid
17 DEALLOCATE getspid
18 END
19 GO
2 AS
3 BEGIN
4 DECLARE @sql nvarchar(500)
5 DECLARE @spid int
6
7 SET @sql='DECLARE getspid CURSOR FOR SELECT spid FROM sysprocesses WHERE dbid=db_id('''+@dbName+''')'
8 EXEC (@sql)
9 OPEN getspid
10 FETCH next FROM getspid INTO @spid
11 WHILE @@fetch_status<>-1
12 BEGIN
13 EXEC('kill '+@spid)
14 FETCH next FROM getspid INTO @spid
15 END
16 CLOSE getspid
17 DEALLOCATE getspid
18 END
19 GO