Home >Database >Mysql Tutorial >更新SQL Server实例中所有数据库表的统计信息

更新SQL Server实例中所有数据库表的统计信息

WBOY
WBOYOriginal
2016-06-07 14:58:101205browse

更新SQLServer实例中所有数据库表的统计信息 无 DECLARE @sql nvarchar(300)?DECLARE UpdateStatsForAllDBs CURSORREAD_ONLYFOR select name from sysdatabases?DECLARE @name nvarchar(255)OPEN UpdateStatsForAllDBs?FETCH NEXT FROM UpdateStatsForAllDBs

更新SQL Server实例中所有数据库表的统计信息 
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
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn