/* SQL Server transactions
per day/hour/minute using sys.dm_os_performance_counters */
-- declarations
DECLARE
@Days
SMALLINT,
@Hours
INT,
@Minutes
BIGINT,
@LastRestart
DATETIME;
-- get last restart date
SELECT
@Days
= DATEDIFF(D, create_date, GETDATE()),@LastRestart = create_date
FROM
sys.databases
WHERE
database_id
= 2;
-- collect days/hours since
last restart
SELECT @Days = CASE WHEN @Days = 0 THEN 1 ELSE @Days END;
SELECT @Hours = @Days * 24;
SELECT @Minutes = @Hours * 60;
-- trans since last restart
SELECT
@LastRestart
[LastRestart],
@@servername [Instance],
cntr_value
[TotalTransSinceLastRestart],
cntr_value
/ @Days [AvgTransPerDay],
cntr_value
/ @Hours [AvgTransPerHour],
cntr_value
/ @Minutes [AvgTransPerMinute]
FROM
sys.dm_os_performance_counters
WHERE
counter_name
= 'Transactions/sec'
AND instance_name = '_Total';
-- trans since last restart
per database
SELECT
@LastRestart
[LastRestart],
@@servername [Instance],
instance_name
[Database_Name],
cntr_value
[TotalTransSinceLastRestart],
cntr_value
/ @Days [AvgTransPerDay],
cntr_value
/ @Hours [AvgTransPerHour],
cntr_value
/ @Minutes [AvgTransPerMinute]
FROM
sys.dm_os_performance_counters
WHERE
counter_name
= 'Transactions/sec'
AND instance_name <> '_Total'
ORDER BY
cntr_value DESC;
Your output will be similar to this:
Take a look at this for more details on the dm_os_performance_counters DMV: sys.dm_os_performance_counters

I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it.. שרת וירטואלי
ReplyDeleteThank you for reading!
DeleteI was basically inspecting through the web filtering for certain data and ran over your blog. I am flabbergasted by the data that you have on this blog. It shows how well you welcome this subject. Bookmarked this page, will return for extra. data science course in jaipur
ReplyDeleteExtremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing. python course in delhi
ReplyDeleteThough I knew a bit of data science already, this post has been so enlightening for me, as I got to understand some of the latest trends in this field through this. I had seen many data science and analytics-based courses online when I was looking for a course for my friend; however, this post guided me in the right direction, and I was able to help my friend with the right suggestion, thanks to this informative post.
ReplyDeletebest training institute for data analytics in pune
Its really helpful. Thanks for such an amazing article.
ReplyDeleteGlad you liked it. Thank you for reading!
Delete