zach14c

update statistics

Dec 26th, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.41 KB | None | 0 0
  1. DECLARE @TSQL nvarchar(2000)
  2.  
  3. -- Filtering system databases and user databases from execution
  4. SET @TSQL = '
  5. IF (DB_ID(''?'') > 4
  6.   AND ''?'' NOT IN(''distribution'',''SSISDB'',''ReportServer'',''ReportServertempdb'')
  7.   )
  8. BEGIN
  9.   PRINT ''********** Rebuilding statistics on database: [?] ************''
  10.   USE [?]; exec sp_updatestats
  11. END
  12. '
  13. -- Executing TSQL for each database
  14. EXEC sp_MSforeachdb @TSQL
Advertisement