Filtering sp_who2 by database
An easy way to improve the usability of sp_who2
is to make a database specific version.
The idea is to leverage the information provided by sp_who2
, but provide a filter for a given database name. This is really handy on either production or development SQL servers with large numbers of databases.
Lets call our version sp_who2db
. The following should be run into your master
database.
You can mark it is a system object using the undocumented sp_MS_MarkSystemObject
proc:
Finally, to use it, just call it as normal:
A similar strategy could be used to filter by blocks, hosts, logins, high CPU or Disk IO etc.
NOTE: The above is tested on MS SQL Server 2008 R2. The columns defined on the @who2
table may need modification for versions other than this, depending on what information sp_who2
provides on those versions.