Sun_china

交流更多,收获更多?

博客园 首页 新随笔 联系 订阅 管理

执行以下脚本,即可解决。

 

declare @dbname varchar(20)
set @dbname='hichina_hmp'  --这里给变量赋的值是要进行还原的数据库的名称

declare @sql nvarchar(500)
declare @spid int  --SPID sqlserver进程ID int
set @sql='declare getspid cursor for
select spid from sysprocesses  where dbid=db_id('''+@dbname+''')'--当前正由进程使用的数据库id  int
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status<>-1  --如果FETCH 语句没有执行失败或此行不在结果集中。
begin
exec('kill '+@spid)  --终止正常连接
fetch next from getspid into @spid
end
close getspid
deallocate getspid

posted on 2012-07-14 10:42  Sun_china  阅读(2750)  评论(0编辑  收藏  举报