解除sql server数据库占用
Posted 王明辉的部落
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解除sql server数据库占用相关的知识,希望对你有一定的参考价值。
use master go declare @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 @spid end close cur_lock deallocate cur_lock
use master
go
declare @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 @spid
end
close cur_lock
deallocate cur_lock
以上是关于解除sql server数据库占用的主要内容,如果未能解决你的问题,请参考以下文章