Reputation:
how to know how many users are connected to a particular database
Upvotes: 1
Views: 3161
Reputation: 300
SELECT COUNT(DISTINCT spid)
FROM master.dbo.sysprocesses
WHERE spid >= 50
AND dbid = DB_ID('MyDBName')
Upvotes: 0
Reputation: 432667
For a simply query, you can use this on SQL 2000 to SQL 2008 (there is no 1:1 replacement for sysprocesses in SQL 2005)
SELECT
COUNT(*)
FROM
MASTER..sysprocesses
WHERE
dbid = DB_ID('MyDBName')
Upvotes: 0