卓越2008

用一颗谦虚的心面对大家,用一颗坚定的心面对困难,用一颗执著的心面对理想,用一颗虔诚的心面对技术。

导航

关闭用户打开的进程处理

Posted on 2007-07-31 10:52  Casm  阅读(264)  评论(0)    收藏  举报
/*   
  关闭用户打开的进程处理   
  
*/
   
  
use   master   
  
go   
    
  
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   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   
    
  
--用法       
  exec   p_killspid     '数据库名'