移除sql数据所有链接用户

use master;
 
go
 
declare @temp nvarchar(20)
 
declare myCurse cursor
 
for
 
select spid
 
from sys.sysprocesses
 
where dbid=DB_ID('数据库名称')--待清理的数据库
 
open myCurse
 
fetch next from myCurse into @temp
 
while @@FETCH_STATUS=0
 
begin
 
exec('kill '+ @temp)
 
fetch next from myCurse into @temp
 
end
 
close myCurse
 
deallocate myCurse;
posted @ 2017-11-02 09:31  暗夜苹果  阅读(250)  评论(0编辑  收藏  举报