-- use [Database Name] go ;with cte as ( SELECT SCHEMA_NAME(o.schema_id) [schema_name], o.schema_id, OBJECT_NAME(S.[OBJECT_ID]) [object_name], S.Name [stat_name], o.create_date, [stats_columns] = COALESCE((STUFF((SELECT CAST(',' + COL_NAME(object_id, column_id) AS varchar(max)) FROM sys.stats_columns WHERE (object_id = s.object_id AND stats_id = s.stats_id) ORDER BY object_id, stats_id FOR xml PATH ('')), 1, 1, '')), ''), s.* FROM sys.Stats s inner join sys.objects o on o.object_id = s.object_id WHERE 1=1 and o.is_ms_shipped = 0 and OBJECTPROPERTY(s.object_id, 'ismsshipped') = 0 and auto_created = 1 and o.create_date < GETDATE() - 90 ) select *, 'DROP STATISTICS [' + cte.[SCHEMA_NAME] + '].[' + cte.[OBJECT_NAME] + '].[' + cte.[stat_name] + ']' drop_stmt, 'CREATE STATISTICS [' + cte.[stat_name] + '] ON [' + cte.[SCHEMA_NAME] + '].[' + cte.[OBJECT_NAME] + '] (' + cte.[stats_columns] + ')' create_stm from cte;
Get auto generated index stats
Subscribe to:
Comments (Atom)
Truncating very large transaction log in full recovery mode
While I always configure transaction log backups for every database in non-simple recovery model, and to compliment it I also have monitorin...
-
When you restore a database, it will also restore all permissions along with it. But what if you are restoring over an existing database and...
-
Event notifications are kinda like a trigger in the sense that they respond to specific event, specifically in response to DDL statements an...
-
-- Health and status of WSFC cluster. These two queries work only if the WSFC has quorum SELECT * FROM sys . dm_hadr_cluster SELECT * F...
No comments:
Post a Comment