时间:2021-07-01 10:21:17 帮助过:31人阅读
你想知道 SQL Server 正在执行什么 SQL 语句吗?然后顺手把这些正在执行的 SQL 语句停掉吗? 请看下面代码 出处: codeproject SQL Server select db_name(dbid) as [Database Name], count(dbid) as [No Of Connections], loginame as [Login Name]from sys.
你想知道 SQL Server 正在执行什么 SQL 语句吗?然后顺手把这些正在执行的 SQL 语句停掉吗?select db_name(dbid) as [Database Name], count(dbid) as [No Of Connections], loginame as [Login Name] from sys.sysprocesses where dbid > 0 group by dbid, loginame
set nocount on declare @databasename varchar(100) declare @query varchar(max) set @query = '' set @databasename = 'xxx' if db_id(@databasename) < 4 begin print 'system database connection cannot be killeed' return end select @query=coalesce(@query,',' )+'kill '+convert(varchar, spid)+ '; ' from master..sysprocesses where dbid=db_id(@databasename) if len(@query) > 0 begin print @query exec(@query) end