DBCC SHOW_STATISTICS (Transact-SQL)DBCC SHOW_STATISTICS (Transact-SQL)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse

DBCC SHOW_STATISTICS 显示表或索引视图的当前查询优化统计信息。DBCC SHOW_STATISTICS displays current query optimization statistics for a table or indexed view. 查询优化器使用统计信息来估计基数或查询结果中的行数,以便创建高质量的查询计划。The query optimizer uses statistics to estimate the cardinality or number of rows in the query result, which enables the Query Optimizer to create a high quality query plan. 例如,查询优化器可以使用基数估计在查询计划中选择索引查找运算符而不是索引扫描运算符,从而通过避免消耗大量资源的索引扫描来提高查询性能。For example, the Query Optimizer could use cardinality estimates to choose the index seek operator instead of the index scan operator in the query plan, improving query performance by avoiding a resource-intensive index scan.

查询优化器将表或索引视图的统计信息存储在统计信息对象中。The Query Optimizer stores statistics for a table or indexed view in a statistics object. 对于表,统计信息对象是根据索引或表列的列表创建的。For a table, the statistics object is created on either an index or a list of table columns. 统计信息对象包含一个带有统计信息的相关元数据的标题、一个带有统计信息对象第一个键列中的值的分布的直方图,以及一个用于度量各列之间的相关性的密度矢量。The statistics object includes a header with metadata about the statistics, a histogram with the distribution of values in the first key column of the statistics object, and a density vector to measure cross-column correlation. 数据库引擎Database Engine可以使用统计信息对象中的任何数据计算基数估计。The 数据库引擎Database Engine can compute cardinality estimates with any of the data in the statistics object. 有关详细信息,请参阅统计信息基数估计 (SQL Server)For more information, see Statistics and Cardinality Estimation (SQL Server).

DBCC SHOW_STATISTICS 根据统计信息对象中存储的数据显示标题、直方图和密度向量。DBCC SHOW_STATISTICS displays the header, histogram, and density vector based on data stored in the statistics object. 使用以下语法,您可以指定表或索引视图以及目标索引名称、统计信息名称或列名。The syntax lets you specify a table or indexed view along with a target index name, statistics name, or column name. 本主题说明如何显示统计信息以及如何理解显示的结果。This topic describes how to display the statistics and how to understand the displayed results.

重要

SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1 开始,sys.dm_db_stats_properties 动态管理视图可用于以编程方式检索包含在统计信息对象中的标头信息,以获取非增量统计信息。Starting in SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1, the sys.dm_db_stats_properties dynamic management view is available to programmatically retrieve header information contained in the statistics object for non-incremental statistics.

重要

SQL Server 2014 (12.x)SQL Server 2014 (12.x) SP2 和 SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1 开始,sys.dm_db_incremental_stats_properties 动态管理视图可用于以编程方式检索包含在统计信息对象中的标头信息,以获取增量统计信息。Starting in SQL Server 2014 (12.x)SQL Server 2014 (12.x) SP2 and SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1, the sys.dm_db_incremental_stats_properties dynamic management view is available to programmatically retrieve header information contained in the statistics object for incremental statistics.

重要

SQL Server 2016 (13.x)SQL Server 2016 (13.x) SP1 CU2 开始,sys.dm_db_stats_histogram 动态管理视图可用于以编程方式检索包含在统计信息对象中的直方图信息。Starting in SQL Server 2016 (13.x)SQL Server 2016 (13.x) SP1 CU2, the sys.dm_db_stats_histogram dynamic management view is available to programmatically retrieve histogram information contained in the statistics object.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

-- Syntax for SQL Server and Azure SQL Database  
  
DBCC SHOW_STATISTICS ( table_or_indexed_view_name , target )   
[ WITH [ NO_INFOMSGS ] < option > [ , n ] ]  
< option > :: =  
    STAT_HEADER | DENSITY_VECTOR | HISTOGRAM | STATS_STREAM  
-- Syntax for Azure Synapse Analytics and Parallel Data Warehouse  

DBCC SHOW_STATISTICS ( table_name , target )   
    [ WITH { STAT_HEADER | DENSITY_VECTOR | HISTOGRAM } [ ,...n ] ]  
[;]

备注

Azure Synapse Analytics 中的无服务器 SQL 池不支持此语法。This syntax is not supported by serverless SQL pool in Azure Synapse Analytics.

备注

若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

参数Arguments

table_or_indexed_view_nametable_or_indexed_view_name
要显示其统计信息的表或索引视图的名称。Name of the table or indexed view for which to display statistics information.

table_nametable_name
包含待显示统计信息的表的名称。Name of the table that contains the statistics to display. 该表不能为外部表。The table cannot be an external table.

目标target
要显示其统计信息的索引、统计信息或列的名称。Name of the index, statistics, or column for which to display statistics information. target 括在括号、单引号或双引号内,或不加引号。target is enclosed in brackets, single quotes, double quotes, or no quotes. 如果 target 是表或索引视图的现有索引或统计信息的名称,则返回有关此目标的统计信息。If target is a name of an existing index or statistics on a table or indexed view, the statistics information about this target is returned. 如果 target 是现有列的名称,且此列中存在自动创建的统计信息,则返回有关该自动创建的统计信息的信息。If target is the name of an existing column, and an automatically created statistics on this column exists, information about that auto-created statistic is returned. 如果列目标中不存在自动创建的统计信息,则返回错误消息 2767。If an automatically created statistic does not exist for a column target, error message 2767 is returned.
Azure Synapse AnalyticsAzure Synapse Analytics并行数据仓库Parallel Data Warehouse中,target 不能为列名称。In Azure Synapse AnalyticsAzure Synapse Analytics and 并行数据仓库Parallel Data Warehouse, target cannot be a column name.

NO_INFOMSGSNO_INFOMSGS
取消严重级别从 0 到 10 的所有信息性消息。Suppresses all informational messages that have severity levels from 0 through 10.

STAT_HEADER | DENSITY_VECTOR | HISTOGRAM | STATS_STREAM [ ,n ]:如果指定上述一个或多个选项,将根据指定的选项限制该语句返回的结果集。STAT_HEADER | DENSITY_VECTOR | HISTOGRAM | STATS_STREAM [ ,n ] Specifying one or more of these options limits the result sets returned by the statement to the specified option or options. 如果没有指定任何选项,则返回所有统计信息。If no options are specified, all statistics information is returned.

STATS_STREAM 为 标识为仅供参考。Identified for informational purposes only. 不支持。Not supported. 不保证以后的兼容性。Future compatibility is not guaranteed.STATS_STREAM is 标识为仅供参考。Identified for informational purposes only. 不支持。Not supported. 不保证以后的兼容性。Future compatibility is not guaranteed.

结果集Result Sets

下表对指定 STAT_HEADER 时结果集中所返回的列进行了说明。The following table describes the columns returned in the result set when STAT_HEADER is specified.

列名称Column name 说明Description
名称Name 统计信息对象的名称。Name of the statistics object.
UpdatedUpdated 上一次更新统计信息的日期和时间。Date and time the statistics were last updated. STATS_DATE 函数是另一种检索此信息的方法。The STATS_DATE function is an alternate way to retrieve this information. 有关详细信息,请参阅此页中的备注部分。For more information, see the Remarks section in this page.
“行”Rows 上次更新统计信息时表或索引视图中的总行数。Total number of rows in the table or indexed view when the statistics were last updated. 如果筛选统计信息或者统计信息与筛选索引对应,该行数可能小于表中的行数。If the statistics are filtered or correspond to a filtered index, the number of rows might be less than the number of rows in the table. 有关详细信息,请参阅统计信息For more information, seeStatistics.
Rows SampledRows Sampled 用于统计信息计算的抽样总行数。Total number of rows sampled for statistics calculations. 如果 Rows Sampled < Rows,显示的直方图和密度结果则是根据抽样行估计的。If Rows Sampled < Rows, the displayed histogram and density results are estimates based on the sampled rows.
步骤Steps 直方图中的梯级数。Number of steps in the histogram. 每个梯级都跨越一个列值范围,后跟上限列值。Each step spans a range of column values followed by an upper bound column value. 直方图梯级是根据统计信息中的第一个键列定义的。The histogram steps are defined on the first key column in the statistics. 最大梯级数为 200。The maximum number of steps is 200.
密度Density 计算公式为 1/统计信息对象第一个键列中的所有值(不包括直方图边界值)的非重复值。Calculated as 1 / distinct values for all values in the first key column of the statistics object, excluding the histogram boundary values. 查询优化器不使用此 Density 值,显示此值的目的是为了与 SQL Server 2008SQL Server 2008 之前的版本实现向后兼容。This Density value is not used by the Query Optimizer and is displayed for backward compatibility with versions before SQL Server 2008SQL Server 2008.
Average Key LengthAverage Key Length 统计信息对象中所有键列的每个值的平均字节数。Average number of bytes per value for all of the key columns in the statistics object.
String IndexString Index Yes 指示统计信息对象包含字符串摘要统计信息,以改进对使用 LIKE 运算符的查询谓词的基数估计;例如 WHERE ProductName LIKE '%Bike'Yes indicates the statistics object contains string summary statistics to improve the cardinality estimates for query predicates that use the LIKE operator; for example, WHERE ProductName LIKE '%Bike'. 字符串摘要统计信息与直方图分开存储,如果统计信息对象为 charvarcharncharnvarcharvarchar(max)nvarchar(max)textntext 类型,则基于其第一个键列创建字符串摘要统计信息。String summary statistics are stored separately from the histogram and are created on the first key column of the statistics object when it is of type char, varchar, nchar, nvarchar, varchar(max), nvarchar(max), text, or ntext..
筛选表达式Filter Expression 包含在统计信息对象中的表行子集的谓词。Predicate for the subset of table rows included in the statistics object. NULL = 未筛选的统计信息。NULL = non-filtered statistics. 有关筛选谓词的详细信息,请参阅创建筛选索引For more information about filtered predicates, see Create Filtered Indexes. 有关筛选统计信息的详细信息,请参阅统计信息For more information about filtered statistics, see Statistics.
Unfiltered RowsUnfiltered Rows 应用筛选表达式前表中的总行数。Total number of rows in the table before applying the filter expression. 如果筛选表达式为 NULL,则 Unfiltered Rows 等于 Rows。If Filter Expression is NULL, Unfiltered Rows is equal to Rows.
持久样本百分比Persisted Sample Percent 持久样本百分比用于未显式指定采样百分比的统计信息更新。Persisted sample percentage used for statistic updates that do not explicitly specify a sampling percentage. 如果值为零,则不为此统计信息设置持久样本百分比。If value is zero, then no persisted sample percentage is set for this statistic.

适用于: SQL Server 2016 (13.x)SQL Server 2016 (13.x) SP1 CU4Applies to: SQL Server 2016 (13.x)SQL Server 2016 (13.x) SP1 CU4

下表对指定 DENSITY_VECTOR 时结果集中所返回的列进行了说明。The following table describes the columns returned in the result set when DENSITY_VECTOR is specified.

列名称Column name 说明Description
All DensityAll Density 密度为 1/非重复值。Density is 1 / distinct values. 结果显示统计信息对象中各列的每个前缀的密度,每个密度显示一行。Results display density for each prefix of columns in the statistics object, one row per density. 非重复值是每个行前缀和列前缀的列值的非重复列表。A distinct value is a distinct list of the column values per row and per columns prefix. 例如,如果统计信息对象包含键列 (A, B, C),结果将报告以下每个列前缀中非重复值列表的密度:(A)、(A,B) 和 (A, B, C)。For example, if the statistics object contains key columns (A, B, C), the results report the density of the distinct lists of values in each of these column prefixes: (A), (A,B), and (A, B, C). 使用前缀 (A, B, C),以下每个列表都是一个非重复值列表:(3, 5, 6)、(4, 4, 6)、(4, 5, 6) 和 (4, 5, 7)。Using the prefix (A, B, C), each of these lists is a distinct value list: (3, 5, 6), (4, 4, 6), (4, 5, 6), (4, 5, 7). 使用前缀 (A, B),相同列值具有以下非重复值列表:(3, 5)、(4, 4) 和 (4, 5)Using the prefix (A, B) the same column values have these distinct value lists: (3, 5), (4, 4), and (4, 5)
Average LengthAverage Length 存储列前缀的列值列表的平均长度(以字节为单位)。Average length, in bytes, to store a list of the column values for the column prefix. 例如,如果列表 (3, 5, 6) 中的每个值都需要 4 个字节,则长度为 12 个字节。For example, if the values in the list (3, 5, 6) each require 4 bytes the length is 12 bytes.
Columns 为其显示 All density 和 Average length 的前缀中的列的名称。Names of columns in the prefix for which All density and Average length are displayed.

下表对指定 HISTOGRAM 选项时结果集中所返回的列进行了说明。The following table describes the columns returned in the result set when the HISTOGRAM option is specified.

列名称Column name 说明Description
RANGE_HI_KEYRANGE_HI_KEY 直方图梯级的上限列值。Upper bound column value for a histogram step. 列值也称为键值。The column value is also called a key value.
RANGE_ROWSRANGE_ROWS 其列值位于直方图梯级内(不包括上限)的行的估算数目。Estimated number of rows whose column value falls within a histogram step, excluding the upper bound.
EQ_ROWSEQ_ROWS 其列值等于直方图梯级的上限的行的估算数目。Estimated number of rows whose column value equals the upper bound of the histogram step.
DISTINCT_RANGE_ROWSDISTINCT_RANGE_ROWS 非重复列值位于直方图梯级内(不包括上限)的行的估算数目。Estimated number of rows with a distinct column value within a histogram step, excluding the upper bound.
AVG_RANGE_ROWSAVG_RANGE_ROWS 直方图步骤中具有重复列值的平均行数,不包括上限。Average number of rows with duplicate column values within a histogram step, excluding the upper bound. 当 DISTINCT_RANGE_ROWS 大于 0 时,通过将 RANGE_ROWS 除以 DISTINCT_RANGE_ROWS 来计算 AVG_RANGE_ROWS。When DISTINCT_RANGE_ROWS is greater than 0, AVG_RANGE_ROWS is calculated by dividing RANGE_ROWS by DISTINCT_RANGE_ROWS. 当 DISTINCT_RANGE_ROWS 为 0 时,AVG_RANGE_ROWS 为直方图步骤返回 1。When DISTINCT_RANGE_ROWS is 0, AVG_RANGE_ROWS returns 1 for the histogram step.

注释Remarks

统计信息更新日期连同直方图密度矢量一起存储在统计信息 blob 对象中,而不是存储在元数据中。Statistics update date is stored in the statistics blob object together with the histogram and density vector, not in the metadata. 如果未读取到任何数据,无法生成统计信息数据,则不会创建统计信息 blob,该日期不可用,且 updated 列为 NULL。When no data is read to generate statistics data, the statistics blob is not created, the date is not available, and the updated column is NULL. 针对谓词不返回任何行或新的空表,筛选的统计信息便是这种情况。This is the case for filtered statistics for which the predicate does not return any rows, or for new empty tables.

直方图Histogram

直方图度量数据集中每个非重复值的出现频率。A histogram measures the frequency of occurrence for each distinct value in a data set. 查询优化器根据统计信息对象第一个键列中的列值来计算直方图,它选择列值的方法是以统计方式对行进行抽样或对表或视图中的所有行执行完全扫描。The query optimizer computes a histogram on the column values in the first key column of the statistics object, selecting the column values by statistically sampling the rows or by performing a full scan of all rows in the table or view. 如果直方图是根据一组抽样行创建的,存储的总行数和非重复值总数则为估计值,且不必为整数。If the histogram is created from a sampled set of rows, the stored totals for number of rows and number of distinct values are estimates and do not need to be whole integers.

若要创建直方图,查询优化器将对列值进行排序,计算与每个非重复列值匹配的值数,然后将列值聚合到最多 200 个连续直方图梯级中。To create the histogram, the query optimizer sorts the column values, computes the number of values that match each distinct column value and then aggregates the column values into a maximum of 200 contiguous histogram steps. 每个梯级都包含一个列值范围,后跟上限列值。Each step includes a range of column values followed by an upper bound column value. 该范围包括介于两个边界值之间的所有可能列值,但不包括边界值自身。The range includes all possible column values between boundary values, excluding the boundary values themselves. 最小排序列值是第一个直方图梯级的上限值。The lowest of the sorted column values is the upper boundary value for the first histogram step.

下面的关系图显示包含六个梯级的直方图。The following diagram shows a histogram with six steps. 第一个上限值左侧的区域是第一个梯级。The area to the left of the first upper boundary value is the first step.

直方图Histogram

对于每个直方图梯级:For each histogram step:

  • 粗线表示上限值 (RANGE_HI_KEY) 和上限值的出现次数 (EQ_ROWS)Bold line represents the upper boundary value (RANGE_HI_KEY) and the number of times it occurs (EQ_ROWS)
  • RANGE_HI_KEY 左侧的纯色区域表示列值范围和每个列值的平均出现次数 (AVG_RANGE_ROWS)。Solid area left of RANGE_HI_KEY represents the range of column values and the average number of times each column value occurs (AVG_RANGE_ROWS). 第一个直方图梯级的 AVG_RANGE_ROWS 始终是 0。The AVG_RANGE_ROWS for the first histogram step is always 0.
  • 点线表示用于估计范围中的非重复值总数 (DISTINCT_RANGE_ROWS) 和范围中的总值数 (RANGE_ROWS) 的抽样值。Dotted lines represent the sampled values used to estimate total number of distinct values in the range (DISTINCT_RANGE_ROWS) and total number of values in the range (RANGE_ROWS). 查询优化器使用 RANGE_ROWS 和 DISTINCT_RANGE_ROWS 计算 AVG_RANGE_ROWS,且不存储抽样值。The query optimizer uses RANGE_ROWS and DISTINCT_RANGE_ROWS to compute AVG_RANGE_ROWS and does not store the sampled values.

查询优化器按照直方图梯级的统计重要性来定义直方图梯级。The query optimizer defines the histogram steps according to their statistical significance. 它使用最大差异算法使直方图中的梯级减至最少,并同时最大化边界值之间的差异。It uses a maximum difference algorithm to minimize the number of steps in the histogram while maximizing the difference between the boundary values. 最大梯级数为 200。The maximum number of steps is 200. 直方图梯级数可以少于非重复值的数目,即使对于边界点少于 200 的列也是如此。The number of histogram steps can be fewer than the number of distinct values, even for columns with fewer than 200 boundary points. 例如,具有 100 个非重复值的列所具有的直方图的边界点可以少于 100。For example, a column with 100 distinct values can have a histogram with fewer than 100 boundary points.

密度向量Density Vector

查询优化器使用密度提高根据相同表或索引视图返回多个列的查询的基数估计。The query optimizer uses densities to enhance cardinality estimates for queries that return multiple columns from the same table or indexed view. 密度向量针对统计信息对象中的列的每个前缀包含一个密度。The density vector contains one density for each prefix of columns in the statistics object. 例如,如果统计信息对象包含键列 CustomerIdItemIdPrice,则根据以下每个列前缀计算密度。For example, if a statistics object has the key columns CustomerId, ItemId and Price, density is calculated on each of the following column prefixes.

列前缀Column prefix 计算密度所基于的对象Density calculated on
(CustomerId)(CustomerId) 具有与 CustomerId 匹配的值的行Rows with matching values for CustomerId
(CustomerId, ItemId)(CustomerId, ItemId) 具有与 CustomerId 和 ItemId 匹配的值的行Rows with matching values for CustomerId and ItemId
(CustomerId, ItemId, Price)(CustomerId, ItemId, Price) 具有与 CustomerId、ItemId 和 Price 匹配的值的行Rows with matching values for CustomerId, ItemId, and Price

限制Restrictions

DBCC SHOW_STATISTICS 不提供空间索引或内存优化的列存储索引的统计信息。DBCC SHOW_STATISTICS does not provide statistics for spatial indexes nor memory-optimized columnstore indexes.

SQL ServerSQL ServerSQL 数据库SQL Database的权限Permissions for SQL ServerSQL Server and SQL 数据库SQL Database

为了查看统计信息对象,用户必须对表具有 SELECT 权限。In order to view the statistics object, the user must have the SELECT permission on the table. 请注意,SELECT 权限必须满足以下要求才能运行此命令:Note that the following requirements exist for SELECT permissions to be sufficient to run the command:

  • 用户必须对统计对象中的所有列具有权限Users must have permissions on all columns in the statistics object
  • 用户必须对筛选条件(如果存在)中的所有列具有权限Users must have permission on all columns in a filter condition (if one exists)
  • 表中不能有行级别安全策略。The table cannot have a row-level security policy.
  • 如果使用动态数据掩码规则屏蔽了统计信息对象中的任何列,除 SELECT 权限外,该用户还必须具有 UNMASK 权限。If any of the columns within a statistics object is masked with Dynamic Data Masking rules, in addition to the SELECT permission, the user must have the UNMASK permission.

SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1 之前的版本中,用户必须是表所有者,或者是 sysadmin 固定服务器角色、db_owner 固定数据库角色或 db_ddladmin 固定数据库角色的成员。In versions before SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1, the user must own the table or the user must be a member of the sysadmin fixed server role, the db_owner fixed database role, or the db_ddladmin fixed database role.

备注

若要将行为更改回 SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1 之前的行为,请使用跟踪标志 9485。To change the behavior back to the pre SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1 behavior, use traceflag 9485.

Azure Synapse AnalyticsAzure Synapse Analytics并行数据仓库Parallel Data Warehouse的权限Permissions for Azure Synapse AnalyticsAzure Synapse Analytics and 并行数据仓库Parallel Data Warehouse

DBCC SHOW_STATISTICS 需要表中的 SELECT 权限或 sysadmin 固定服务器角色的成员身份、db_owner 固定数据库角色的成员身份或 db_ddladmin 固定数据库角色的成员身份。DBCC SHOW_STATISTICS requires SELECT permission on the table or membership in the sysadmin fixed server role, the db_owner fixed database role, or the db_ddladmin fixed database role.

Azure Synapse AnalyticsAzure Synapse Analytics并行数据仓库Parallel Data Warehouse 的限制与局限Limitations and Restrictions for Azure Synapse AnalyticsAzure Synapse Analytics and 并行数据仓库Parallel Data Warehouse

DBCC SHOW_STATISTICS 显示控制节点级别的 Shell 数据库中存储的统计信息。DBCC SHOW_STATISTICS shows statistics stored in the Shell database at the Control node level. 它不显示由计算节点上的 SQL ServerSQL Server 自动创建的统计信息。It does not show statistics that are auto-created by SQL ServerSQL Server on the Compute nodes.

外部表不支持 DBCC SHOW_STATISTICS。DBCC SHOW_STATISTICS is not supported on external tables.

示例:SQL ServerSQL ServerSQL 数据库SQL DatabaseExamples: SQL ServerSQL Server and SQL 数据库SQL Database

A.A. 返回所有统计信息Returning all statistics information

以下示例显示 AdventureWorks2012AdventureWorks2012 数据库中 Person.Address 表的 AK_Address_rowguid 索引的所有统计信息。The following example displays all statistics information for the AK_Address_rowguid index of the Person.Address table in the AdventureWorks2012AdventureWorks2012 database.

DBCC SHOW_STATISTICS ("Person.Address", AK_Address_rowguid);  
GO  

B.B. 指定 HISTOGRAM 选项Specifying the HISTOGRAM option

该示例将为 Customer_LastName 显示的统计信息限制为 HISTOGRAM 数据。This limits the statistics information displayed for Customer_LastName to the HISTOGRAM data.

DBCC SHOW_STATISTICS ("dbo.DimCustomer",Customer_LastName) WITH HISTOGRAM;  
GO  

示例:Azure Synapse AnalyticsAzure Synapse Analytics并行数据仓库Parallel Data WarehouseExamples: Azure Synapse AnalyticsAzure Synapse Analytics and 并行数据仓库Parallel Data Warehouse

C.C. 显示一个统计信息对象的内容Display the contents of one statistics object

以下示例显示 DimCustomer 表中 Customer_LastName 统计信息的内容。The following example displays the contents of the Customer_LastName statistics on the DimCustomer table.

-- Uses AdventureWorks  
--First, create a statistics object  
CREATE STATISTICS Customer_LastName   
ON AdventureWorksPDW2012.dbo.DimCustomer (LastName);  
GO  
DBCC SHOW_STATISTICS ("dbo.DimCustomer",Customer_LastName);  
GO  

结果显示标题、密度矢量和直方图的一部分。The results show the header, the density vector, and part of the histogram.

DBCC SHOW_STATISTICS 结果DBCC SHOW_STATISTICS results

另请参阅See Also

统计信息Statistics
CREATE INDEX (Transact-SQL)CREATE INDEX (Transact-SQL)
CREATE STATISTICS (Transact-SQL)CREATE STATISTICS (Transact-SQL)
DROP STATISTICS (Transact-SQL)DROP STATISTICS (Transact-SQL)
sp_autostats (Transact-SQL)sp_autostats (Transact-SQL)
sp_createstats (Transact-SQL)sp_createstats (Transact-SQL)
STATS_DATE (Transact-SQL)STATS_DATE (Transact-SQL)
更新统计信息 (Transact-SQL)UPDATE STATISTICS (Transact-SQL)
sys.dm_db_stats_properties (Transact-SQL)sys.dm_db_stats_properties (Transact-SQL)
sys.dm_db_stats_histogram (Transact-SQL) sys.dm_db_stats_histogram (Transact-SQL)
sys.dm_db_incremental_stats_properties (Transact-SQL)sys.dm_db_incremental_stats_properties (Transact-SQL)