GO
/****** Object: StoredProcedure [dbo].[mysp_updatestats] Script Date: 2023/6/7 15:02:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- 在没有权限运行 Exec sp_updatestats 时,用这个存储过程来更新数据库中所有表的统计信息
-- 当前采用的是 UPDATE STATISTICS [dbo].[mytablename] WITH FULLSCAN 的方式
-- 作者:huang wanjing
-- 执行方式: exec [mysp_updatestats]
create procedure [dbo].[mysp_updatestats]
as
-- required so it can update stats on ICC/IVs
set ansi_warnings on
set ansi_padding on
set arithabort on
set concat_null_yields_null on
set numeric_roundabort off
declare @exec_stmt_head nvarchar(4000) -- "UPDATE STATISTICS [sysname].[sysname] "
declare @updated_count int
declare @skipped_count int
declare @sch_id int
declare @schema_name sysname
declare @table_name sysname
declare @table_id int
declare @table_type char(2)
declare @schema_table_name nvarchar(640) -- assuming sysname is 128 chars, 5x that, so it's > 128*4+4
--declare @compatlvl tinyint
declare
在没有权限运行 Exec sp_updatestats 时,用这个存储过程来更新数据库中所有表的统计信息
于 2023-06-07 15:47:49 首次发布
该文章提供了一个名为mysp_updatestats的SQLServer存储过程的代码,用于更新数据库中所有表的统计信息。当没有权限运行Execsp_updatestats时,可以使用此存储过程。它遍历所有用户表,检查是否有禁用的聚簇索引,并对每个表执行UPDATESTATISTICS命令,使用FULLSCAN选项。

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



