ITPub博客

首页 > 应用开发 > IT综合 > 有关statistics

有关statistics

原创 IT综合 作者:kitesky 时间:2007-07-26 07:26:48 0 删除 编辑
有关statistics[@more@]

-- 1 查看/修改 数据库auto create statistics选项值
sp_dboption 'CommunityServer', 'auto create statistics'
sp_dboption 'CommunityServer', 'auto create statistics', 'TRUE'

-- 2 查看表中索引index或统计collection的分布统计信息
DBCC SHOW_STATISTICS ('cs_Sections', '_WA_Sys_ParentID_7D0E9093')

-- 3 为某表更新统计信息
-- 本示例仅更新表 authors 的索引 au_id_ind 的分发信息
UPDATE STATISTICS authors au_id_ind

-- 4为数据库中所有表更新统计信息
EXEC sp_updatestats

-- 5 查看数据库中所有index的统计时间
SELECT
[Table Name] = o.name,
[Index Name] = i.name,
[Statistics Date] = STATS_DATE(i.id, i.indid)
FROM sysobjects o, sysindexes i
WHERE o.id = i.id
ORDER BY [Statistics Date] DESC
GO

--6 为没有最新统计信息的表生成修改统计信息SQL
SELECT
'UPDATE STATISTICS ' + o.name + ' ' + i.name
FROM sysobjects o, sysindexes i
WHERE o.id = i.id and o.type = 'U' and STATS_DATE(i.id, i.indid) is null

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/66009/viewspace-928151/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Oral Aticle 1
请登录后发表评论 登录
全部评论

注册时间:2009-04-22

  • 博文量
    273
  • 访问量
    2225399