Check Database Activity Script | Database Journal

Check Database Activity Script

Oct 18, 2004
1 minute read


This SQL script from Richard Ding checks the current database activity in SQL server by using a cursor to loop through the db name list into which table joins pull out rows from sysprocesses and syslockinfo. The result of table names currently being used as well as the type of locks set on them are then displayed. The script differs with sp_who or sp_who2 in that it shows what object and lock the spid is accessing. It is useful in monitoring processes such as DBCC DBREINDEX. Running this script constantly will disclose a dynamic pattern of a certain process to better understand what it is doing.

It has been tested on SQL 7 and 2000.

Download the Script

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.