使用sys.dm_db_index_physical_stats [英] Using sys.dm_db_index_physical_stats

查看:69
本文介绍了使用sys.dm_db_index_physical_stats的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

以下脚本正常工作正常:

Following script works OK:

=============== ========

=======================

DECLARE @db_id SMALLINT; 

DECLARE @object_id INT; 

 

SET @db_id = DB_ID(N'AdventureWorks2016'); 

SET @object_id = OBJECT_ID(N'AdventureWorks2016.Person.Address'); 

 

IF @db_id IS NULL 

BEGIN; 

   打印N'无效的数据库'; 

END; 

ELSE如果@object_id为NULL 

BEGIN; 

   打印N'无效对象'; 

END; 

ELSE 

BEGIN; 

    SELECT * FROM sys.dm_db_index_physical_stats(@ db_id,@ object_id,NULL,NULL,'LIMITED'); 


END; 

GO

DECLARE @db_id SMALLINT; 
DECLARE @object_id INT; 
 
SET @db_id = DB_ID(N'AdventureWorks2016'); 
SET @object_id = OBJECT_ID(N'AdventureWorks2016.Person.Address'); 
 
IF @db_id IS NULL 
BEGIN; 
    PRINT N'Invalid database'; 
END; 
ELSE IF @object_id IS NULL 
BEGIN; 
    PRINT N'Invalid object'; 
END; 
ELSE 
BEGIN; 
    SELECT * FROM sys.dm_db_index_physical_stats(@db_id, @object_id, NULL, NULL , 'LIMITED'); 
END; 
GO

=======================

=======================

是否可以获得仅显示相关表的表名,索引名和avg_fragmentation_in_percent列的结果?

提前感谢您的帮助!

Victor < span style ="">

Victor

Victor

推荐答案

获取表名,加入object_id上的sys.objects。要获取索引名称,请在object_id和index_id上加入sys.indexes。如果您只想查看avg_fragmentation_in_percent列,则只在SELECT中包含该列而不是包括所有列。

To get the table name, join with sys.objects on object_id. To get the index name, join sys.indexes on object_id and index_id. If you only want to see avg_fragmentation_in_percent column, then include only that column in the SELECT instead of including all.


这篇关于使用sys.dm_db_index_physical_stats的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆