Skip to content

Instantly share code, notes, and snippets.

@mvalipour
Created April 2, 2016 16:21
Show Gist options
  • Select an option

  • Save mvalipour/9ceb7db700b2c90eeff7366b734b7c93 to your computer and use it in GitHub Desktop.

Select an option

Save mvalipour/9ceb7db700b2c90eeff7366b734b7c93 to your computer and use it in GitHub Desktop.
Update SQL Statistics with Full Scan
DECLARE @sql nvarchar(MAX);
SELECT @sql = (SELECT 'UPDATE STATISTICS [' + DB_NAME() + '].[' + rtrim(sc.name) + '].[' + rtrim(so.name) + '] WITH FULLSCAN, ALL;' + CHAR(13) + CHAR(10)
from sys.sysobjects so
join sys.schemas sc
on so.uid = sc.schema_id
where so.xtype = 'U'
FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)');
PRINT @sql
EXEC (@sql)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment