Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE @db_id SMALLINT;
- DECLARE @object_id INT;
- SET @db_id = DB_ID(N'wfm');
- SET @object_id = OBJECT_ID(N'wfm.dbo.Lab_Employee_Time_Off');
- 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 OBJECT_NAME(ips.OBJECT_ID) AS 'TableName'
- ,i.NAME AS 'IndexName'
- ,ips.index_id
- ,ips.index_type_desc
- ,ips.avg_fragmentation_in_percent
- ,ips.avg_page_space_used_in_percent
- ,ips.page_count
- FROM sys.dm_db_index_physical_stats(@db_id, @object_id, NULL, NULL, 'DETAILED') ips
- INNER JOIN sys.indexes i ON (ips.object_id = i.object_id)
- AND (ips.index_id = i.index_id)
- ORDER BY i.name, avg_fragmentation_in_percent DESC
- END;
- GO
Add Comment
Please, Sign In to add comment