码迷,mamicode.com
首页 > 数据库 > 详细

解除sql server数据库占用

时间:2016-10-26 00:52:00      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:div   margin   use   占用   weight   size   declare   locate   数据库名   

 

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数据库占用

标签:div   margin   use   占用   weight   size   declare   locate   数据库名   

原文地址:http://www.cnblogs.com/Sabre/p/5998691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!