use master
go
declare @dbName nvarchar(50)
set @dbName='dbname' --数据库名
declare @spid nvarchar(20) 
declare cur_lock cursor for 
SELECT DISTINCT request_session_id FROM master.sys.dm_tran_locks WHERE resource_type = 'DATABASE' AND resource_database_id = db_id(@dbName)
open cur_lock 
fetch cur_lock into @spid 
while @@fetch_status=0 
begin 
exec( 'kill '+@spid) 
fetch Next From cur_lock into @spid
end 
close cur_lock
deallocate cur_lock

 

use master

go

declare @dbName nvarchar(50)

set @dbName='dbname' --数据库名

declare @spid nvarchar(20)

declare cur_lock cursor for

SELECT DISTINCT request_session_id FROM master.sys.dm_tran_locks WHERE resource_type = 'DATABASE' AND resource_database_id = db_id(@dbName)

open cur_lock

fetch cur_lock into @spid

while @@fetch_status=0

begin

exec( 'kill '+@spid)

fetch Next From cur_lock into @spid

end

close cur_lock

deallocate cur_lock

相关文章:

  • 2021-11-01
  • 2021-11-08
  • 2022-01-19
  • 2022-12-23
  • 2021-05-02
  • 2022-12-23
  • 2022-03-03
猜你喜欢
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2021-07-07
相关资源
相似解决方案