Statistics shown on an orders table of 10,000 rows: the histogram lists Saffron 5 rows, Spice 995 and Tea 9,000, and the optimizer uses an Index Seek with a Key Lookup for Saffron and a Clustered Index Scan for Tea

SQL Statistics: How SQL Server Estimates Row Counts

SQL statistics are small summaries of your data that tell the optimizer how many rows a query will return. This post builds an orders table with one rare value and one common value, reads the histogram, compares estimated and actual rows in the plans, and shows a stale statistic fixed with UPDATE STATISTICS. Every result comes from SQL Server 2025.

Read More
Bar chart of the distance from Seattle to four stops: Spokane 368.7 kilometers, Chicago 2,796.1, Philadelphia 3,829.0 and Boston 4,011.0, with Seattle to Boston highlighted as 2,492.3 miles

Distance Between Two Points on the Earth With the geography Type

The distance between two points on the earth takes one method call once you store the points as a geography value. This post builds a small table of five US cities, turns latitude and longitude into points, and measures with STDistance in meters, kilometers and miles. It also compares the answer with a flat map formula and a sphere formula, and shows the error for swapped arguments.

Read More
Four table rows drawn as bars made of five parts: header, fixed data, null block, variable block and variable data. The rows add up to 46, 58, 40 and 68 bytes

Data Row Space Usage: Estimate Row Size Before the Table Grows

Data row space usage is the number of bytes one row takes, and every table size estimate starts there. This post adds up the five parts of a row for a small table of rooms and checks the result against what SQL Server reports. It also shows that NULL does not shrink a fixed-length column, and turns 100,000 rows a day into pages and megabytes.

Read More