Interview Answer (Simple English, Clear Flow)
“When a client sends a SQL query, it first reaches the SQL Server through a protocol called TDS – Tabular
Data Stream. This goes through the SQL Server Network Interface (SNI), which handles how the request
comes in — whether it’s via Shared Memory, TCP/IP, or Named Pipes.”
“Then, the query enters the SQL Server Database Engine, where it is handled in two parts: the Relational
Engine and the Storage Engine.”
Relational Engine (Query Processor)
“The Relational Engine first parses the query to check if it is written correctly (syntax and semantics).
Then it checks if a similar query plan already exists in the plan cache. If not, the Query Optimizer creates
a new plan — it could be a quick plan or a fully optimized one depending on the query. Once the plan is
ready, the Query Executor runs the plan and connects to the Storage Engine to get or update the data.”
Storage Engine (Accessing Data)
“Now, the Storage Engine checks if the query is a read (SELECT) or a write (like INSERT, UPDATE,
DELETE).”
If it’s a SELECT query:
“It checks in memory (Buffer Cache) if the data is already available. If yes, that’s called soft parsing — it
just reads and returns. If not, that’s called hard parsing — it fetches from disk into memory, then returns
the result.”
If it’s a Non-SELECT query (INSERT, UPDATE, DELETE):
“SQL Server first writes this change to the Transaction Log (LDF file) using the Log Manager. Then, it
updates the data in memory (Buffer Cache). That updated page in memory is called a dirty page —
because it’s changed in memory but not yet saved to disk.”
“Later, SQL Server will write that dirty page to the data file (MDF or NDF) using a process called
Checkpoint or Lazy Writer.”
Lock & Transaction Control
“The Lock Manager ensures there are no conflicts — for example, two users updating the same data at
the same time. The Transaction Manager controls the transaction flow — and makes sure everything is
committed or rolled back properly.”
Data Files in Physical Storage
• MDF is the main data file — it stores your actual tables, indexes, etc.
• NDF is optional — extra storage files for spreading data.
• LDF is the transaction log file — it stores all changes to help with rollback and recovery.
Example Summary You Can Use in Interview:
“So to summarize: The query is parsed, optimized, and executed. If it’s a SELECT, data is fetched from
memory or disk. If it’s a non-SELECT, it’s logged first, then memory is updated, then eventually the
changes go to disk. Everything is stored in MDF/NDF files, and logs go into the LDF file. SQL Server
ensures consistency with transaction and locking mechanisms.”
If you’d like, I can now help you memorize this flow with a one-page cheat sheet or practice question
answers. Want that?