查看数据库中每个表的行数
use 数据库名
go
SELECT a.name ,b.rows
FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id
WHERE (a.type = 'u') AND (b.indid IN (0, 1)) order by b.rows desc
查看最大连接数
SELECT @@MAX_CONNECTIONS
查看指定数据库的连接数
SELECT * FROM master.dbo.sysprocesses WHERE dbid IN
(
SELECT dbid FROM master.dbo.sysdatabases
WHERE NAME='DB_WMS_KZJ'
)
获取当前SQL服务器所有的连接详细信息
SELECT * FROM sysprocesses
获取自上次启动 SQL Server服务 以来连接或试图连接的次数
SELECT @@CONNECTIONS
查看连接数
select hostname 主机名,count(*) 连接数量 from master.dbo.sysprocesses group by hostname order by count(*) desc
或者
SELECT login_name,
Count(0) user_count
FROM Sys.dm_exec_requests dr WITH(nolock)
RIGHT OUTER JOIN Sys.dm_exec_sessions ds WITH(nolock)
ON dr.session_id = ds.session_id
RIGHT OUTER JOIN Sys.dm_exec_connections dc WITH(nolock)
ON ds.session_id = dc.session_id
WHERE ds.session_id > 50
GROUP BY login_name
ORDER BY user_count DESC
参考:
https://m.656463.com/wenda/rhcxSQLSERVERzljcdzdljs6496_77
https://blog.csdn.net/w13511069150/article/details/115396501