SQL QueriesSQL Tips

System Statistical Function in SQL

By 09/12/2022 January 2nd, 2024 No Comments

Problem Statement:

Often, we need to gather system statistics regarding running SQL Server Instances, such as the number of total connections attempted to SQL Server instance since its start, or the time that SQL Server spent in active operations, etc. Microsoft brought us a separate set of system functions to retrieve the system-related statistics. All system statistical functions are nondeterministic. This means these functions do not always return the same results every time they are called, even with the same set of input values.

SQL Server has several in-built system statistical functions returning the system-related statistics.

                           

Code Snippet :

SELECT ‘Connections’ FunctionNM, @@CONNECTIONS
UNION
SELECT ‘CPUBusy’, @@CPU_BUSY
UNION
SELECT ‘IDLE’, @@IDLE
UNION
SELECT ‘IOBusy’, @@IO_BUSY
UNION
SELECT ‘PacketErrors’, @@PACKET_ERRORS
UNION
SELECT ‘PackReceived’, @@PACK_RECEIVED
UNION
SELECT ‘PackSent’, @@PACK_SENT
UNION
SELECT ‘TimeTicks’, @@TIMETICKS
UNION
SELECT ‘TotalErrors’, @@TOTAL_ERRORS
UNION
SELECT ‘TotalRead’, @@TOTAL_READ

Code Output:

If you are Hire A SQL Developer in Brisbane, Technology Cue is here. Contact us.

Leave a Reply