今天在用sql server 2008 恢复数据库时提示有其他用户连接,无法继续恢复了。很头疼,呼唤百度帮忙。结果查到了如下的sql 语句,可以结束用户连接。


begin
declare @spid varchar(20)
declare @dbname varchar(20)
select @dbname='databasename'--换成要操作的数据库名称

declare #spid cursor for
select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
open #spid
fetch next from #spid into @spid
while @@fetch_status=0
begin
exec('kill '+@spid)
fetch next from #spid into @spid
end
close #spid
deallocate #spid
end

 

 

相关文章:

  • 2021-09-12
  • 2021-09-06
  • 2022-03-01
  • 2021-08-11
  • 2022-01-09
  • 2021-12-19
猜你喜欢
  • 2021-04-13
  • 2021-10-10
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
相关资源
相似解决方案