Select count(distinct hostname) from master..sysprocesses where hostname > ''
use master goselect count(*) 当前连接到SQLSERVER的用户数 from dbo.sysprocesses where status<>'background' exec sp_who2
use master goselect count(*) 当前连接到SQLSERVER的用户数 from dbo.sysprocesses where status<>'background' exec sp_who2
--连接的用户名 select hostname from master..sysprocesses where hostname<>'' group by hostname --连接的用户数 select count(distinct(hostname)) from master..sysprocesses where hostname<>''
select count(distinct hostname) from master..sysprocesses where hostname > ''
可以取出连接数了,如何能够知道连接到指定数据库的连接数,比如连接到数据库aaa的用户连接数是多少?
select * from master..sysprocesses where dbid=db_id(N'yourdbname')
declare @db varchar(255) select @db=数据库名 select count(distinct(hostname)) from master..sysprocesses where hostname<>'' and dbid=(select dbid from master..sysdatabases where name=@db)
select count(distinct hostname) from master..sysprocesses where hostname > '' and dbid=db_id('aaa')
where hostname > ''
goselect count(*) 当前连接到SQLSERVER的用户数 from dbo.sysprocesses where status<>'background'
exec sp_who2
goselect count(*) 当前连接到SQLSERVER的用户数 from dbo.sysprocesses where status<>'background'
exec sp_who2
select hostname from master..sysprocesses where hostname<>'' group by hostname
--连接的用户数
select count(distinct(hostname)) from master..sysprocesses where hostname<>''
select @db=数据库名
select count(distinct(hostname)) from master..sysprocesses where hostname<>'' and dbid=(select dbid from master..sysdatabases where name=@db)
and dbid=db_id('aaa')