📁 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. How do you choose a primary key and clustered key for a SQL Server table? Compare int and bigint identity with GUIDs (NEWID, NEWSEQUENTIALID and version 7), natural versus surrogate keys, and explain what makes a good clustered index key.

    Covers surrogate versus natural keys, identity integers versus GUID variants, why SQL Server's uniqueidentifier sort order matters for v7 GUIDs, and the properties of a good clustered key (narrow, unique, static, ever-increasing).

    Mid-Level Theory Database Design Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  2. When would you denormalise a SQL Server schema, and how? Compare persisted computed columns, indexed views and reporting tables, and explain what denormalisation costs you in writes and consistency.

    Covers when denormalisation is justified and the SQL Server tools for it (persisted computed columns, indexed views, summary and reporting tables, read models), with their write, consistency and operational costs.

    Mid-Level Theory Database Design Β· πŸ”— 1 follow-ups Β· πŸ›  1 real-world
  3. How would you enforce a business rule that spans two tables in SQL Server, such as uniqueness across a join?
    Intermediate Theory Database Design
  4. What is an untrusted constraint in SQL Server, how does it happen, and why does it matter?
    Junior Theory Database Design
  5. What is database normalisation and why does it matter? Explain insert, update and delete anomalies, and walk me through first, second and third normal form using an orders example.

    Covers the purpose of normalisation, the three data anomalies it removes, and 1NF, 2NF and 3NF applied step by step to an orders table in SQL Server.

    Beginner Theory Database Design Β· πŸ”— 2 follow-ups
  6. What do Boyce-Codd normal form, fourth normal form and fifth normal form fix that third normal form does not? Give an example of each, and tell me how much they matter in a real SQL Server schema.

    Covers BCNF (determinants that are not candidate keys), 4NF (independent multi-valued facts) and 5NF (join dependencies), with examples and their practical relevance for SQL Server OLTP design.

    Intermediate Theory Database Design Β· πŸ”— 2 follow-ups
  7. What constraints does SQL Server give you — primary key, foreign key, unique, check, default and NOT NULL — and why would you enforce business rules in the database rather than only in your .NET code?

    Covers each SQL Server constraint type, what it enforces and creates (indexes), how they help the optimiser, and why rules belong in the database as well as in application validation.

    Junior Theory Database Design Β· πŸ”— 3 follow-ups
  8. Design the schema for a small online shop in SQL Server: customers, products, orders and order lines. Write the DDL with data types, primary and foreign keys, unique and check constraints and the indexes you would add on day one, and explain each choice.

    A T-SQL design exercise: DDL for customers, products, orders and order lines with deliberate type choices, named constraints, foreign key indexes, a rowversion and the first query-driven indexes, explained as an interviewer expects.

    Mid-Level Sql Database Design Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  9. Deleting old customers from a SQL Server database has become very slow, and while the delete job runs other sessions are blocked. The tables have foreign keys, some created WITH NOCHECK years ago. How do you diagnose and fix it?

    A debugging scenario covering unindexed foreign keys that force child-table scans during parent deletes, lock escalation from large deletes, cascades, and untrusted constraints (WITH NOCHECK) that stop the optimiser using them.

    Senior Debugging Database Design Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  10. Code review: a pull request adds SQL Server tables where every string is nvarchar(max), there are no foreign keys, product attributes go in an entity-attribute-value table, order tags are stored as comma-separated ids in one column, and dates and prices use datetime and money. What do you flag, in what order, and what does the fixed design look like?

    A senior code review of a SQL Server table design: nvarchar(max) keys, missing foreign keys, an EAV table, comma-separated values, datetime and money, ranked by severity with a rewrite and review close-out.

    Senior CodeReview Database Design Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  11. Your SQL Server database is heading towards several terabytes and many tenants. How would you design it to scale? Discuss table partitioning, archiving old data, multi-tenant database layouts, and choosing between Azure SQL Hyperscale and elastic pools.

    A staff-level architecture question on scaling SQL Server and Azure SQL: partitioning (and what it does not do), archiving with partition switching, tenant layouts, Hyperscale versus elastic pools, read scale-out and sharding.

    Staff / Architect Architecture Database Design Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. Why does AddWithValue cause plan cache bloat as well as implicit conversions, and how do you detect it?

    Covers how SqlParameterCollection.AddWithValue infers nvarchar with the value's length, why that creates one cached plan per length and implicit conversions on varchar columns, and how to detect and fix it.

    Senior Debugging Indexes
  13. What is the difference between a clustered and a non-clustered index in SQL Server? Explain the B+ tree structure, what a heap is, and how SQL Server finds a row through each.

    Covers the B+ tree layout of SQL Server rowstore indexes, clustered indexes as the table itself, heaps and RIDs, non-clustered indexes and their row locators, and how seeks and lookups find a row.

    Junior Theory Indexes Β· πŸ”— 2 follow-ups
  14. You have a composite index on (CustomerId, OrderDate, Status) in SQL Server. Which queries can seek on it and which can't? Explain why column order matters, the leftmost-prefix rule, and how you decide the order of columns.

    Covers how a composite B+ tree index is sorted, the leftmost-prefix rule, equality-then-range column ordering, which predicates give seeks versus scans, and when to create a second index instead.

    Intermediate Theory Indexes Β· πŸ”— 2 follow-ups
  15. What is a covering index in SQL Server, and how do INCLUDE columns differ from key columns? What is a key lookup, when does it become a problem, and how do you decide whether to cover a query?

    Covers key lookups and RID lookups, covering indexes, INCLUDE versus key columns, the tipping point where the optimiser switches to a scan, and the write and storage cost of covering.

    Intermediate Theory Indexes Β· πŸ”— 2 follow-ups
  16. What is a filtered index in SQL Server and when would you use one, for example for soft-deleted rows or a status column? Explain the gotcha with parameterised queries, filtered unique indexes, and the other limitations you need to know.

    Covers filtered index syntax and use cases (soft delete, sparse status values, optional unique keys), why parameterised queries often cannot use them, the required SET options, filter predicate limits and filtered statistics.

    Mid-Level Theory Indexes Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  17. What are columnstore indexes in SQL Server? Explain rowgroups, segments, the delta store and batch mode, when you would put a non-clustered columnstore index on an OLTP table, and what it costs.

    Covers columnstore storage (rowgroups, column segments, compression, segment elimination), the delta store and tuple mover, batch mode execution, clustered versus non-clustered columnstore, real-time operational analytics and the trade-offs.

    Mid-Level Theory Indexes Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  18. What are selectivity and density in SQL Server? How do they relate to statistics and histograms, how does the optimiser use them to estimate rows, and why does it often ignore an index on a low-selectivity column?

    Covers selectivity and density definitions, the statistics object (header, density vector, 200-step histogram), how estimates are derived for literals, parameters and local variables, the seek-versus-scan tipping point, and when low-selectivity indexes are still useful.

    Mid-Level Theory Indexes Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  19. What is index fragmentation in SQL Server, and what does fill factor do? Explain page splits, logical fragmentation versus page density, rebuild versus reorganise, whether fragmentation still matters on SSDs and Azure SQL, and what index maintenance strategy you would actually run.

    Covers page splits, logical fragmentation and low page density, fill factor trade-offs, REBUILD versus REORGANIZE (online, resumable, statistics side effects), why fixed 5%/30% thresholds are outdated on SSD storage, and a measured maintenance strategy for SQL Server and Azure SQL.

    Mid-Level Theory Indexes Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  20. What does SARGable mean in SQL Server? Show me predicates that prevent an index seek, such as functions on columns, arithmetic, implicit conversions, leading wildcards and ISNULL, and rewrite each one so it can seek.

    Covers what makes a predicate SARGable, the common non-sargable patterns (functions and arithmetic on columns, implicit conversions, leading wildcards, ISNULL/COALESCE, OR across columns, catch-all queries) and their rewrites, including computed columns and the CAST to date exception.

    Mid-Level Sql Indexes Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

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