SQL SERVER – Find Total Sessions by Database

Today we will see a very simple script that I often use during my  Comprehensive Database Performance Health Check. Let us find Total Sessions By Database.

SELECT DB_NAME(resource_database_id) AS DatabaseName, COUNT(*) AS TotalSessions
FROM sys.dm_tran_locks
GROUP BY DB_NAME(resource_database_id)
order by db_name(resource_database_id)

That’s it. It is a very simple script that will list all the sessions for a particular database with a database name and total sessions.

Red-eyed tree frog with the title Find Total Sessions by Database

Here is the six-part blog post series I have written based on my last 10 years of experience helping with the Comprehensive Database Performance Health Check. I strongly recommend you to read them as they walk you through my business model.

Here are my few recent videos and I would like to know what is your feedback about them. Do not forget to subscribe SQL in Sixty Seconds series.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

SQL DMV, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Threads Not Counted for Max Worker Threads
Next Post
SQL SERVER – Check If a Column Exists 2016 Onwards

Related Posts

2 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.