首页 > 代码库 > sql-删除无效sql链接

sql-删除无效sql链接

create proc dtLink(@dbName varchar(50) --数据库名称)as--查询临时表是否存在if(OBJECT_ID(temp..db) is not null)begin    drop table #TempTableend--创建临时表create table #TempTable(spid int,ecid int,status varchar(32),loginname varchar(32),hostname varchar(32),blk int,dbname varchar(32),cmd varchar(32),request_id int)--给临时表插入数据insert into #TempTableexec sp_who/*select * from #TempTablewhere spid = @@SPID*/--定义游标declare cus_dtLink cursor scroll forselect spid from #TempTablewhere dbname = @dbNameand status = sleepingand spid <> @@SPID--定义变量declare @spid int--打开游标open cus_dtLinkdeclare @sql varchar(200)--执行游标fetch next from cus_dtLink into @spid--循环杀连接while(@@FETCH_STATUS = 0)begin    select @sql = kill  + cast(@spid as varchar(20))    exec(@sql)    fetch next from cus_dtLink into @spidend--关闭游标close cus_dtLink--释放游标deallocate cus_dtLink

 

sql-删除无效sql链接