zoukankan      html  css  js  c++  java
  • [转]索引检查命令

    DBCC SHOWCONTIG用法

    下面举例来说明DBCC SHOWCONTIGDBCC REDBINDEX的使用方法。以应用程序中Employee数据作为例子,在 SQL ServerQuery analyzer输入命令:

    use database_name
    declare @table_id int
    set @table_id=object_id('Employee')
    dbcc showcontig(@table_id)

     

    输出结果:

    DBCC SHOWCONTIG scanning 'Employee' table
    Table'Employee' (1195151303); index ID: 1database ID: 53
    TABLE level scan performed.
    - Pages Scanned..: 179
    - Extents Scanned24
    - Extent Switches24
    - Avg. Pages per Extent7.5
    - Scan Density [Best Count:Actual Count].: 92.00% [23:25]
    - Logical Scan Fragmentation 0.56%
    - Extent Scan Fragmentation .: 12.50%
    - Avg. Bytes Free per Page552.3
      
    Avg. Page Density (full)93.18%
    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

     

    通过分析这些结果可以知道该表的索引是否需要重构。如下描述了每一行的意义:

     

    信息                                            描述
    Pages Scanned                     表或索引中的长页数
    Extents Scanned                  表或索引中的长区页数
    Extent Switches                   DBCC遍历页时从一个区域到另一个区域的次数
    Avg. Pages per Extent          相关区域中的页数
    Scan Density[Best Count:Actual Count] Best Count是连续链接时的理想区域改变数,
    Actual Count是实际区域改变数,Scan Density100%表示没有分块。
    Logical Scan Fragmentation   扫描索引页中失序页的百分比
    Extent Scan Fragmentation     不实际相邻和包含链路中所有链接页的区域数
    Avg. Bytes Free per Page        扫描页面中平均自由字节数
    Avg. Page Density (full)          平均页密度,表示页有多满

     

    从上面命令的执行结果可以看的出来,Best count23 Actual Count25这表明orders表有分块需要重构表索引。下面通过DBCC DBREINDEX来重构表的簇索引。

     

    3. DBCC DBREINDEX 用法

    重建指定数据库中表的一个或多个索引。

     

    语法

    DBCC DBREINDEX
        (    
            
    [ 'database.owner.table_name'    
                [ , index_name
                    [ , fillfactor 
    ]
                ] 
            ] 
        )     

     

    参数

    'database.owner.table_name'

    是要重建其指定的索引的表名。数据库、所有者和表名必须符合标识符的规则。有关更多信息,请参见使用标识符。如果提供 database owner 部分,则必须使用单引号 (') 将整个 database.owner.table_name 括起来。如果只指定 table_name,则不需要单引号。

     

    index_name

    是要重建的索引名。索引名必须符合标识符的规则。如果未指定 index_name 或指定为 ' ',就要对表的所有索引进行重建。

     

    fillfactor

    是创建索引时每个索引页上要用于存储数据的空间百分比。fillfactor 替换起始填充因子以作为索引或任何其它重建的非聚集索引(因为已重建聚集索引)的新默认值。如果 fillfactor 0DBCC DBREINDEX 在创建索引时将使用指定的起始 fillfactor

     

    同样在Query Analyzer中输入命令:

    dbcc dbreindex('database_name.dbo.Employee','',90)

     

     

    然后再用DBCC SHOWCONTIG查看重构索引后的结果:

    DBCC SHOWCONTIG scanning 'Employee' table
    Table'Employee' (1195151303); index ID: 1database ID: 53
    TABLE level scan performed.
    - Pages Scanned..: 178
    - Extents Scanned23
    - Extent Switches22
    - Avg. Pages per Extent7.7
    - Scan Density [Best Count:Actual Count].: 100.00% [23:23]
    - Logical Scan Fragmentation 0.00%
    - Extent Scan Fragmentation .: 0.00%
    - Avg. Bytes Free per Page509.5
    - Avg. Page Density (full)93.70%
    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    通过结果我们可以看到Scan Denity100%

  • 相关阅读:
    数组的基本操作
    面向对象
    继承
    JavaBean规范
    JVM内存模型
    数组的排序
    this
    访问控制权限
    数组
    方法的重载
  • 原文地址:https://www.cnblogs.com/killkill/p/1374380.html
Copyright © 2011-2022 走看看