📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

1325 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

Phase 12 — SQL Server

SQL Server and Azure SQL for .NET engineers: database design and normalisation, indexing, execution plans and query tuning, T-SQL features, and transactions, locking and isolation levels.

  1. A lookup by account number has an index on a varchar(20) column, yet from your .NET API it scans the whole table and uses lots of CPU, while the same query typed into SSMS seeks instantly. The plan shows CONVERT_IMPLICIT. How do you diagnose it and fix it in EF Core, Dapper and ADO.NET?

    Covers how .NET strings become nvarchar parameters, why an nvarchar parameter against a varchar column converts the column and blocks seeks (collation nuances), finding it in plans and the plan cache, and fixing it with IsUnicode(false)/HasColumnType, DbString/AnsiString and typed SqlParameters.

    Senior Debugging Indexes Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  2. You own a write-heavy SQL Server table (orders, events or telemetry) that has accumulated a dozen indexes. How do you decide which indexes it should have? Explain the write cost of each index, how you find unused and missing indexes with DMVs, and the caveats of those DMVs.

    Covers the per-index write, log, memory and blocking cost, building an index set from real query patterns, finding unused indexes with sys.dm_db_index_usage_stats and missing indexes with the missing-index DMVs and Query Store, their caveats (resets, no column-order or write-cost awareness), safe removal by disabling first, and Azure SQL automatic tuning.

    Senior Theory Indexes Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  3. What does 'Reason For Early Termination: Time Out' mean in an execution plan, and what would you do about it?

    What an optimiser timeout in a SQL Server plan really means (a capped search, not a wall-clock failure), when it matters, and how to make the query easier to optimise.

    Intermediate Theory Query Performance
  4. Why can the estimated cost percentages in a SQL Server execution plan be misleading, even in an actual plan?

    Why the cost percentages in SQL Server plans are always estimates, the cases where they lie badly (bad cardinality, scalar UDFs, remote calls, parallelism), and how to find the real hotspot.

    Intermediate Theory Query Performance
  5. What is the ascending key problem in SQL Server statistics, and how do you deal with it?

    Why new rows beyond the last histogram step get badly under-estimated in SQL Server, how the legacy and new cardinality estimators differ, and how to keep statistics current after loads.

    Mid-Level Theory Query Performance Β· πŸ›  1 real-world
  6. How does Parameter Sensitive Plan optimisation in SQL Server 2022 work, and what doesn't it fix?

    How SQL Server 2022's Parameter Sensitive Plan (PSP) optimisation builds a dispatcher plan with query variants, and the parameter-sniffing cases it leaves unsolved.

    Senior Debugging Query Performance
  7. Why might a plan forced in Query Store stop being used, and how would you notice?

    Why a Query Store forced plan can silently stop being used, how to detect forcing failures, and how to manage forced plans over time.

    Mid-Level Theory Query Performance
  8. Your SQL Server shows low CPU but many requests waiting on RESOURCE_SEMAPHORE. What is happening and what do you do?

    Diagnosing memory grant starvation (RESOURCE_SEMAPHORE waits) when CPU is low, and fixing it at the query, server and Resource Governor level.

    Senior Theory Query Performance Β· πŸ›  1 real-world
  9. How does the SQL Server query optimiser turn a T-SQL statement into an execution plan? Walk me through parsing, binding (algebrisation), cost-based optimisation, the plan cache and execution, and explain why the optimiser looks for a good-enough plan rather than the best one.

    Covers the SQL Server query processing pipeline: parse, bind/algebrise, trivial plan and cost-based optimisation phases, plan caching and reuse, and execution, with what the optimiser's estimates depend on.

    Intermediate Theory Query Performance Β· πŸ”— 3 follow-ups
  10. How do you read a SQL Server execution plan? Explain estimated versus actual plans, the main operators (index seek, index scan, key lookup, nested loops, hash match and merge join), the warnings you look for, and what you check first when a query is slow.

    Covers reading SQL Server execution plans: estimated vs actual plans, right-to-left data flow, seek, scan, key lookup, nested loops, hash match, merge join, sort, warnings, and estimated vs actual rows as the first check.

    Intermediate Theory Query Performance Β· πŸ”— 3 follow-ups
  11. What are statistics in SQL Server and how does cardinality estimation use them? Explain histograms and density vectors, when statistics are created and auto-updated, what the cardinality estimator version changes, and the symptoms of stale or misleading statistics.

    Covers SQL Server statistics objects (header, density vector, 200-step histogram), auto-create and auto-update thresholds, sampling, CE versions tied to compatibility level, ascending-key and correlated-predicate problems, and how stale statistics show up in plans.

    Mid-Level Theory Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. A stored procedure (or an EF Core query) is fast when you run it in SSMS but takes 30 seconds from your .NET API, and Query Store shows its duration jumped yesterday with no code change. How do you diagnose it, and what are your options to fix it?

    Covers diagnosing parameter sniffing: why SSMS and the app get different plans (ARITHABORT and other SET options, local variables), finding the regressed plan in Query Store, comparing compiled and runtime parameter values, and fixes from OPTION (RECOMPILE) and OPTIMIZE FOR to plan forcing, Query Store hints, PSP optimisation and code changes.

    Senior Debugging Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  13. How does the SQL Server plan cache work? Explain how plans are matched and reused, simple versus forced parameterisation, why SQL built by string concatenation bloats the cache, and how sp_executesql and 'optimize for ad hoc workloads' help.

    Covers the SQL Server plan cache: cache keys (text hash, SET options, database), object types (Adhoc, Prepared, Proc), simple and forced parameterisation, single-use plan bloat from concatenated SQL and variable parameter lengths, sp_executesql, optimize for ad hoc workloads and how to measure cache health.

    Mid-Level Theory Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  14. What is Query Store in SQL Server and Azure SQL? Explain what it captures, how you use it to find regressed or expensive queries, how plan forcing and Query Store hints work, the settings that matter, and what's on by default in Azure SQL.

    Covers Query Store: captured query text, plans, runtime and wait statistics per interval, built-in reports, finding regressions, plan forcing and its failure modes, Query Store hints, key settings (capture mode, size, interval, cleanup, READ_ONLY flip) and Azure SQL defaults including automatic plan correction.

    Mid-Level Theory Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  15. The execution plan shows a green 'Missing Index' suggestion with a 95% estimated impact, and the missing index DMVs list dozens more. How do you read these suggestions, what are their limitations, and how do you decide which indexes to actually create?

    Covers SQL Server missing index suggestions in plans and the sys.dm_db_missing_index_* DMVs: how they are generated, what impact means, their limitations (column order, overlap, no write cost, include bloat, reset on restart), and a workload-based process for turning them into real indexes.

    Mid-Level Theory Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  16. Here is a slow query: it lists a customer's recent open orders with product names and takes 2 seconds. Tune it step by step in front of me. How do you measure it, what do you look for in the plan (scans, seeks, key lookups, sorts), what do you change, and how do you prove the change worked?

    Covers a hands-on T-SQL tuning walkthrough: baseline with SET STATISTICS IO, TIME and the actual plan, reading the plan for scans, residual predicates, key lookups and sorts, fixing SARGability and indexing, rewriting the query, and proving the improvement with logical reads and Query Store.

    Mid-Level Sql Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  17. Fifteen minutes after a release, your Azure SQL Database CPU hits 100% and the API starts timing out. Walk me through how you find the query responsible using Query Store and DMVs, how you mitigate it in minutes, how you fix it properly, and what you put in place so it doesn't happen again.

    Covers a production incident on Azure SQL: confirming CPU saturation with sys.dm_db_resource_stats, finding the culprit with sys.dm_exec_requests and Query Store, telling a plan regression from a new or changed query, mitigating with plan forcing, rollback or scaling, fixing the root cause, and preventing it with release gates and alerts.

    Senior RealWorldScenario Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  18. What is a memory grant in SQL Server? Explain how the grant is sized, what happens when it is too small (sort and hash spills to tempdb) or too large (RESOURCE_SEMAPHORE waits), how memory grant feedback works in recent versions, and how you diagnose and fix grant problems.

    Covers query memory grants: which operators need memory, how grants are sized from estimates and row width, spills to tempdb and their warnings, oversized grants and RESOURCE_SEMAPHORE waits, memory grant feedback (batch, row mode, percentile and persistence), and diagnosis with DMVs, Query Store and hints.

    Senior Theory Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  19. A query runs in 50 ms in your dev and test environments but takes 8 seconds in production, with the same code and the same indexes. How do you investigate it methodically, and what are the usual causes?

    Covers a methodical approach to environment-specific slowness: comparing actual plans, data volume and distribution, statistics, parameter values, compatibility level and configuration, blocking and resource limits between dev and production, and fixing the real cause rather than the symptom.

    Mid-Level Debugging Query Performance Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  20. What is an indexed view in SQL Server, and when is it worth the write cost?
    Junior Theory SQL Features

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me