index fragmentation

DECLARE @db_id  INT
DECLARE @obj_id INT
DECLARE @idx_id INT

SET @db_id = DB_ID(N'mydb')
SET @obj_id = OBJECT_ID(N'dbo.mytable')

SELECT @idx_id = index_id 
FROM sys.indexes 
WHERE object_id = @obj_id
  AND name = 'myidx'

SELECT *
FROM sys.dm_db_index_physical_stats(@db_id, @obj_id, @idx_id, NULL, 'DETAILED')
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s