脚本的奇怪结果

时间:2018-07-03 05:12:52

标签: sql-server-2014

希望您能启发我。

我正在运行此脚本:

SELECT DISTINCT 
    DB_Name(Database_id) AS 'DatabaseName',
    V.OBJECT_ID AS ObjectId,
    Object_Name(V.Object_id) AS ObjectName,
    V.Index_ID AS IndexId,
    U.name as IndexName,
    V.Index_Type_Desc AS IndexDescription,
    V.avg_record_size_in_bytes,
    V.record_count,
    STATS_DATE(V.object_id, V.index_id) AS 'lastupdated',
    CONVERT([varchar](512), round(Avg_Fragmentation_In_Percent, 3)) AS 'AvgFragmentationInPercent'
FROM 
    sys.dm_db_index_physical_stats(db_id(), NULL, NULL, NULL, 'detailed') V
JOIN 
    sys.indexes U ON V.object_id = U.object_id AND V.index_id = U.index_id
WHERE 
    V.OBJECT_ID IS NOT NULL
    AND U.name = 'Add_Remove_Programs_64_DATA_AK'
ORDER BY 
    IndexName

我得到了意料之外的结果:

DatabaseName    ObjectId    ObjectName  IndexId IndexName   IndexDescription    avg_record_size_in_bytes    record_count    lastupdated AvgFragmentationInPercent
CM_PBN  101575400   Add_Remove_Programs_64_DATA 3   Add_Remove_Programs_64_DATA_AK  NONCLUSTERED INDEX  96,899  1966    2018-06-07 16:54:04.610 100
CM_PBN  101575400   Add_Remove_Programs_64_DATA 3   Add_Remove_Programs_64_DATA_AK  NONCLUSTERED INDEX  98,536  41  2018-06-07 16:54:04.610 0
CM_PBN  101575400   Add_Remove_Programs_64_DATA 3   Add_Remove_Programs_64_DATA_AK  NONCLUSTERED INDEX  104,797 112316  2018-06-07 16:54:04.610 3.561

您可以看到结果包含一个索引,但显示了三遍。我不知道为什么。所以我希望我只是看不见明显的原因而只是盲目。非常感谢您的努力。

0 个答案:

没有答案