标签:
1、创建统计语法:
CREATE STATISTICS statistics_name ON { table_or_indexed_view_name } ( column [ ,...n ] ) [ WHERE <filter_predicate> ] [ WITH [ [ FULLSCAN | SAMPLE number { PERCENT | ROWS } | STATS_STREAM = stats_stream ] [ , ] ] [ NORECOMPUTE ] ] ; <filter_predicate> ::= <conjunct> [AND <conjunct>] <conjunct> ::= <disjunct> | <comparison> <disjunct> ::= column_name IN (constant ,…) <comparison> ::= column_name <comparison_op> constant <comparison_op> ::= IS | IS NOT | = | <> | != | > | >= | !> | < | <= | !<
以上有3个词比较陌生,看看:
示例:
CREATE STATISTICS ST_NAME ON Person(Name) --在Person表的Name列上创建统计
查看结果:
CREATE STATISTICS ST_NAME ON PersonTenThousand (Name) WHERE Name IS NOT NULL --过滤统计 WITH FULLSCAN; --全扫描
2、更新统计语法
UPDATE STATISTICS ON < table_name > [ . <index_name> ] WITH FULLSCAN {, NORECOMPUTE }
说明:
示例:
UPDATE STATISTICS Person --默认抽样更新该表上的全部统计信息UPDATE STATISTICS Person IX_NAME --全扫描更新该表上的统计IX_NAME信息 WITH FULLSCAN;
3、删除统计语法
DROP STATISTICS table.statistics_name | view.statistics_name [ ,...n ]
示例:
DROP STATISTICS PersonTenThousand.ST_NAME --删除Person表上的统计ST_NAME
4、查看统计的操作:
查看Person表的IX_NAME统计:
DBCC SHOW_STATISTICS(Person,IX_NAME)
输出如下:
关于这些列的说明http://technet.microsoft.com/zh-cn/library/ms174384(v=sql.100).aspx
5、配置数据库的统计的自动创建
ALTER DATABASE Test SET AUTO_CREATE_STATISTICS OFF/ON
6、配置数据库统计的自动更新
ALTER DATABASE Test SET AUTO_UPDATE_STATISTICS OFF/ON
7、异步更新的配置
ALTER DATABASE Test SET AUTO_UPDATE_STATISTICS_ASYNC OFF/ON
8、存储过程配置统计自动更新开启
EXEC sp_autostats ‘ta1‘,‘ON‘ --表ta1所有的统计开启自动更新
9、存储过程配置统计,精确到单个统计对象
EXEC sp_autostats ‘ta1‘,‘OFF‘,IX_COLUMN2 --表ta1上的索引IX_COLUMN2开启自动更新
标签:
原文地址:http://www.cnblogs.com/mingxuantongxue/p/4488854.html