Four steps for a check constraint on existing data: find the two negative areas, fail to add the rule too early with Msg 547, fix the values and add the rule, then watch an update to minus 5 get rejected

Check Constraint on Existing Data: Clean First, Then Enforce

A check constraint on existing data fails if even one row already breaks the rule. This post finds bad values in a small table of lakes, cleans them, adds the constraint, tightens it with an upper limit, and writes a rule across two columns. It also shows how NULL and WITH NOCHECK behave. 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