
DECLARE @sql nvarchar(300)
DECLARE UpdateStatsForAllDBs CURSOR
READ_ONLY
FOR select name from sysdatabases
DECLARE @name nvarchar(255)
OPEN UpdateStatsForAllDBs
FETCH NEXT FROM UpdateStatsForAllDBs INTO @name
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
SET @sql = N'EXEC ' + QUOTENAME(@name) + N'.sys.sp_updatestats'
EXEC sp_executesql @sql
END
FETCH NEXT FROM UpdateStatsForAllDBs INTO @name
END
CLOSE UpdateStatsForAllDBs
DEALLOCATE UpdateStatsForAllDBs
GO



中级程序员
by: 东城 发表于:2016-05-12 09:21:42 顶(0) | 踩(0) 回复
回复评论