Created
October 11, 2024 14:59
-
-
Save JosiahSiegel/b5d6be663e6fc9a87f228c0f3d35746b to your computer and use it in GitHub Desktop.
Update statistics to incremental for partitioned tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--ALTER DATABASE [MyDB] SET AUTO_CREATE_STATISTICS ON (INCREMENTAL = ON) | |
SELECT DISTINCT 'UPDATE STATISTICS ' + QUOTENAME(sc.name) + '.' + QUOTENAME(object_name(S.object_id)) + ' (' + QUOTENAME(s.name) + ') WITH INCREMENTAL = ON' | |
FROM sys.tables T | |
INNER JOIN sys.schemas sc ON t.schema_id = sc.schema_id | |
INNER JOIN sys.indexes I | |
ON T.object_id = I.object_id | |
INNER JOIN sys.data_spaces DS | |
ON I.data_space_id = DS.data_space_id | |
INNER JOIN sys.stats S | |
ON I.object_id = S.object_id | |
WHERE | |
DS.type = 'PS' | |
AND S.is_incremental = 0 | |
AND S.name NOT LIKE 'CCI%' --Ignore columnstore indexes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment