Skip to content

Statistics are not collected when creating new table and indexes and loading data after. #990

@Niritl-Madeira

Description

@Niritl-Madeira

Statistics are not collected when modification_counter is null although new records exist

SQL Server version and edition
Microsoft SQL Server 2019 (RTM-CU32-GDR) (KB5065222) - 15.0.4445.1 (X64) Aug 13 2025 11:07:18 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)

Microsoft SQL Server 2022 (RTM-CU23) (KB5078297) - 16.0.4236.2 (X64) Jan 22 2026 17:50:56 Copyright (C) 2022 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 26200: ) (Hypervisor)

Version of the script
Version: 2025-12-20 18:52:13

What command are you executing?
Use DemoDB
GO

CREATE TABLE T1(c1 int);
CREATE INDEX Ix1 on T1(C1);
INSERT INTO t1 (c1)
SELECT value
FROM GENERATE_SERIES(1, 999);

SELECT sp.stats_id, name, filter_definition, last_updated, rows, rows_sampled, steps, unfiltered_rows, modification_counter
FROM sys.stats AS stat
CROSS APPLY sys.dm_db_stats_properties(stat.object_id, stat.stats_id) AS sp
WHERE stat.object_id = object_id('dbo.T1');

EXECUTE master.dbo.IndexOptimize
@databases = 'DemoDB',
@FragmentationLow = NULL,
@FragmentationMedium = NULL,
@FragmentationHigh = NULL,
@UpdateStatistics = 'ALL',
@OnlyModifiedStatistics = 'Y',
@LogToTable = 'Y'

EXEC sp_helpstats 'dbo.T1';

What output are you getting?
No statistica are collected when new table is create with indexes and data is loaded after index creation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions