SQL Server emergency? Email pinal@sqlauthority.com with URGENT in the subject line.

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.

Continue Reading

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.

Continue Reading