Home > Database > Mysql Tutorial > 找到活动的SQL连接,并杀掉它!【MSSQL】

找到活动的SQL连接,并杀掉它!【MSSQL】

WBOY
Release: 2016-06-07 14:56:21
Original
1128 people have browsed it

你想知道 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 语句停掉吗?
请看下面代码
出处: codeproject
SQL Server
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
Copy after login
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
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template