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
Three results side by side. INSERT with OUTPUT shows the two new rows with SeedID 6 and 7. UPDATE with OUTPUT shows old and new Packets for four rows. DELETE with OUTPUT shows the two removed rows, Mint and Okra

Output Clause in Simple Examples: See the Rows You Just Changed

The OUTPUT clause shows the exact rows an INSERT, UPDATE or DELETE just changed, using the inserted and deleted tables. This post covers the output clause in simple examples with a small table of seed packets. It also shows how to save the rows with INTO, what error you get for the wrong table, and why triggers change the rules.

Read More