首页 > 代码库 > 解除sql server数据库占用
解除sql server数据库占用
use mastergodeclare @dbName nvarchar(50)set @dbName=‘Supervise_changchun‘ --数据库名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 @spidend close cur_lockdeallocate cur_lock
use master
go
declare @dbName nvarchar(50)
set @dbName=‘Supervise_changchun‘ --数据库名
declare @spid nvarchar(20)
declare cur_lock cursor for
SELECTDISTINCT request_session_id FROM master.sys.dm_tran_locksWHERE 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)
fetchNext From cur_lock into @spid
end
close cur_lock
deallocate cur_lock
解除sql server数据库占用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。