DBAtlas · Database operations atlas

Update statistics

SQL ServerMaintenance

Command

-- Single table, full scan:
UPDATE STATISTICS dbo.Customer WITH FULLSCAN;

-- Specific statistic, with sampling:
UPDATE STATISTICS dbo.Customer IX_Customer_Email WITH SAMPLE 30 PERCENT;

-- Bulk for the whole database (user tables), sampled:
EXEC sys.sp_updatestats;

What it does

Updates the column/index statistics the optimizer uses; ensures correct execution plans and cardinality estimates.

When to use it

After large data changes/loads, on plan regressions; an index rebuild already fully refreshes statistics (not needed separately).

Caution

FULLSCAN is accurate but expensive; it creates I/O load on large tables. sp_updatestats updates only changed statistics and uses default sampling. A repeat UPDATE STATISTICS on the same index after an index REBUILD is unnecessary.

Open in DBAtlas →

Related