Skip to content
  • English Deutsch

benjamin-abt.com

Performance is a feature | Cloud - AI - Azure - .NET - Sustainability

  • Home
  • Blog
  • Portfolio
    • Overview
    • Workshops & Training
    • Publications
  • Contact
  • Home
  • Blog

MSSQL Query Statistics

MSSQL Query Statistics
January 16, 2023 3 min read BEN ABT
MSSQL

This article was written in 2023. Versions, tools and recommendations may have changed since then. Newer posts are collected under Blog.

MSSQL Live Query statistics are a valuable tool for software developers working with Microsoft SQL Server (MSSQL). These statistics provide information about the performance of individual queries, allowing developers to identify and troubleshoot any issues that may be impacting the efficiency of their database.

There are several types of query statistics available in MSSQL. One of the most useful is the execution plan, which shows the steps that the database engine takes to execute a query. This can be especially helpful when dealing with complex queries, as it allows developers to see exactly how the database is processing the request and identify any potential bottlenecks.

Another type of query statistic is the actual execution statistics. These statistics provide detailed information about the resources used by a query, including the amount of CPU time, the number of reads and writes to the database and the duration of the query. This information can help developers understand the performance of their queries and identify opportunities for optimization.

Query statistics can also be useful for identifying issues with index usage. If a query is performing poorly, it may be because it is not using the most appropriate indexes. By analyzing the query statistics, developers can determine if this is the case and make any necessary changes to improve the performance of their queries. In addition to helping with performance troubleshooting and optimization, query statistics can also be used for capacity planning. By analyzing the resource usage of queries over time, developers can get a sense of the demand on their database and plan for future growth.

Activate Query Statistics

To enable query statistics in Microsoft SQL Server (MSSQL), you will need to use the SET STATISTICS IO and SET STATISTICS TIME Transact-SQL commands. These commands allow you to enable or disable the display of query statistics for your current session.

SQL
 1-- Enable query statistics
 2SET STATISTICS IO ON;
 3SET STATISTICS TIME ON;
 4
 5-- Run query
 6SELECT * FROM NewsLikes;
 7
 8-- Disable query statistics
 9SET STATISTICS IO OFF;
10SET STATISTICS TIME OFF;
  • The SET STATISTICS IO command enables the display of input/output (IO) statistics for your query, including the number of logical reads and physical reads that are performed by the query.
  • The SET STATISTICS TIME command enables the display of the CPU time and elapsed time for the query.

The output in my case is:

Shell
 1(0 rows affected)
 2Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, page server reads 0, read-ahead reads 0, page server read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob page server reads 0, lob read-ahead reads 0, lob page server read-ahead reads 0.
 3Table 'NewsLikes'. Scan count 0, logical reads 2, physical reads 0, page server reads 0, read-ahead reads 0, page server read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob page server reads 0, lob read-ahead reads 0, lob page server read-ahead reads 0.
 4
 5(1 row affected)
 6
 7 SQL Server Execution Times:
 8   CPU time = 0 ms,  elapsed time = 0 ms.
 9SQL Server parse and compile time: 
10   CPU time = 0 ms, elapsed time = 0 ms.
11
12 SQL Server Execution Times:
13   CPU time = 0 ms,  elapsed time = 0 ms.
14
15Completion time: 2023-01-16T08:41:41.0467462+01:00

This shows me my queries are fine and I have good indexes :-)


In summary, query statistics are an essential tool for software developers working with MSSQL. They provide valuable information about the performance and resource usage of individual queries, allowing developers to troubleshoot and optimize their database for maximum efficiency.

Related articles

Advanced Usage of MSSQL Indexed Views in EF Core

Jan 13, 2025 - 5 min read

Advanced Usage of MSSQL Indexed Views in EF Core

In the world of Microsoft SQL Server , views are a powerful tool for simplifying complex data queries. Simple views offer no real …

Create a Fulltext Catalog with EF Core .NET Migrations for MSSQL

Oct 29, 2022 - 4 min read

Create a Fulltext Catalog with EF Core .NET Migrations for MSSQL

A full-text catalog in Microsoft SQL Server is a specialized storage that is used to store and manage full-text indexes for one or more …

Use a MSSQL Server 2017 Docker Container with Full-Text Search Support

Oct 27, 2019 - 2 min read

Use a MSSQL Server 2017 Docker Container with Full-Text Search Support

By default, there is currently no Full-Text Search Support in the Docker Images for Microsoft SQL Server 2017 or 2019 by Microsoft. The only …


BEN ABT

BEN ABT

Ben is Chief Engineering Officer and Principal Software Engineer at Medialesson.de, with a strong focus on .NET and Microsoft Azure. In his professional role, he designs and builds highly scalable platforms for hybrid and cloud-based scenarios. He also advises companies and C-levels on migrating to the sovereign cloud.

He runs myCSharp.de, the largest and most active German-speaking C# community forum, actively contributes to both his own and external open-source projects and regularly shares his knowledge through his blog, at community events, conferences and as a writer for technical magazines.

Let's Work Together

Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

New Platforms

Modernization

Training & Consulting

Contact Me
X Facebook LinkedIn WhatsApp
Back Next Blog Post

Open for work!

Contact Me
BEN ABT BEN ABT Software Engineer · Microsoft MVP Passionate about .NET, Azure, performance optimization and sustainable software engineering.

Medialesson GmbH Logo

Microsoft MVP Logo

Recent posts

View all
Stop Using nginx as Your Default Static File Server in Docker

Stop Using nginx as Your Default Static File Server in …

Oct 24, 2026
Containerizing .NET in 2026 Without a Dockerfile

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026
Problem Details in ASP.NET Core and .NET 11

Problem Details in ASP.NET Core and .NET 11

Oct 5, 2026
Resilience in .NET with Microsoft.Extensions.Resilience

Resilience in .NET with Microsoft.Extensions.Resilience

Sep 21, 2026
What Matters in ASP.NET Core 11

What Matters in ASP.NET Core 11

Sep 14, 2026

Tags

.NET (192) Csharp (96) ASP.NET Core (48) Azure (41) DevOps (17) Docker (14) Microsoft (14) EF Core (11) Microsoft MVP (11) AI (10) GitHub (10) GitHub Copilot (10) ASP.NET (9) Security (9) Synology (9) Architecture (8) Raspberry (8) Azure Functions (7) Cloudflare (7) Bicep (6)
benjamin-abt.com

About BEN

Benjamin Abt is a Software Engineer, Platform Architect and Microsoft MVP specializing in .NET, Azure, cloud architecture, performance optimization and sustainable software development.

Connect

  • Follow me on GitHub
  • Follow me on LinkedIn
  • Follow me on Mastodon
  • Microsoft MVP profile
  • Follow SchwabenCode on GitHub
  • Follow me on X

Quick Links

  • Portfolio
  • Blog
  • Workshops & Training
  • Publications
  • Get in Touch
  • Sitemap
Open for Work

© Copyright Benjamin Abt & SchwabenCode | 2011 - 2026

Content licensed under CC BY 4.0 unless otherwise noted.

  • Impressum
  • Privacy
  • Contact