SQL Server Interview Question #136
What are statistics in SQL Server?
Indexes & Query Performance Senior Advanced
Detailed Explanation
Statistics contain information about the distribution of values in columns and indexes. The query optimizer uses them to estimate how many rows different operations are likely to return.
Accurate cardinality estimates are important because they influence join algorithms, memory grants, access methods, and operator choices. SQL Server can automatically create and update statistics when configured to do so, but large or unusual workloads may require targeted statistics maintenance and investigation.
Code Example
UPDATE STATISTICS dbo.Products;
-- Or update one named statistic:
-- UPDATE STATISTICS dbo.Products IX_Products_CategoryId;