Saturday, August 7, 2010

Scriplet: Display Connections Per User & Database

A quick script to list out which users have how many connections with which databases.

-- Display users' connections per database.
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

0 comments:

Post a Comment