use mastergo if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[p_killspid]GO create proc p_killspid@dbname varchar(200) --要关闭进程的数据库名as declare @sql nvarchar(500) declare @spid nvarchar(20) declare #tb cursor forselect spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)open #tbfetch next from #tb into @spidwhile @@fetch_status=0begin exec('kill '+@spid)fetch next from #tb into @spidend close #tbdeallocate #tbgo --用法 exec p_killspid '库'