liveBook · Manning

SQL

As explained in 100 SQL Server Mistakes and How to Avoid Them

SQL is a declarative language for querying and managing relational data.

SQL describes the result to return rather than prescribing each execution step. SQL Server parses the query, resolves object names, and passes a normalized query tree to the Query Optimizer, which chooses a plan using metadata such as data types, statistics, and indexes. section 1.2.1

Mistake: treating NOLOCK as harmless

A product page queries dbo.Products and uses CASE to display stock status. The example also uses WITH (NOLOCK), explicitly flagged as a mistake requiring further review; do not copy that hint without understanding its operational consequences. section 1.2.1

SELECT
     ProductName
   , ProductDescription AS Description
   , CASE
       WHEN StockQty >= 10
           THEN N'In Stock'
       WHEN StockQty > 0 AND StockQty < 10
           THEN CAST(StockQty AS NVARCHAR) + ' left in stock'
       ELSE 'Out of stock'
     END
   , ProductImage
FROM dbo.Products WITH (NOLOCK)
WHERE ProductID = @ProductID

Inspect the complete SELECT statement, including the CASE expression, parameterized filter, product columns, and NOLOCK hint. section 1.2.1

Figure 1.3 The flow of a query through the Database Engine

Follow the query path from the application protocol through SQL Server's protocol layer and relational engine. section 1.2.1

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Traces parsing, name resolution, query-tree creation, and optimization, while stopping short of detailed optimizer internals.
Examples
Uses a parameterized product SELECT with CASE-based stock messages and a NOLOCK caution.
What you can do after
Evaluate/understand how SQL Server transforms a declarative query into an execution plan.
How it connects
Connects SQL with query optimization, parsers, relational engines, statistics, indexes, data types, TDS, and SNI.

Also explained in

Compare how 25 books explain SQL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.