IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[IndexStats]') AND type in (N'U')) DROP TABLE [dbo].[IndexStats] GO CREATE TABLE [dbo].[IndexStats]( [IndexColumn] sysname NOT NULL, [database_id] [smallint] NULL, [object_id] [int] NULL, [index_id] [int] NULL, [partition_number] [int] NULL, [index_type_desc] [nvarchar](60) NULL, [alloc_unit_type_desc] [nvarchar](60) NULL, [index_depth] [tinyint] NULL, [index_level] [tinyint] NULL, [avg_fragmentation_in_percent] [float] NULL, [fragment_count] [bigint] NULL, [avg_fragment_size_in_pages] [float] NULL, [page_count] [bigint] NULL, [avg_page_space_used_in_percent] [float] NULL, [record_count] [bigint] NULL, [ghost_record_count] [bigint] NULL, [version_ghost_record_count] [bigint] NULL, [min_record_size_in_bytes] [int] NULL, [max_record_size_in_bytes] [int] NULL, [avg_record_size_in_bytes] [float] NULL, [forwarded_record_count] [bigint] NULL, [compressed_page_count] [bigint] NULL ) GO INSERT INTO [dbo].[IndexStats] ([IndexColumn] ,[database_id] ,[object_id] ,[index_id] ,[partition_number] ,[index_type_desc] ,[alloc_unit_type_desc] ,[index_depth] ,[index_level] ,[avg_fragmentation_in_percent] ,[fragment_count] ,[avg_fragment_size_in_pages] ,[page_count] ,[avg_page_space_used_in_percent] ,[record_count] ,[ghost_record_count] ,[version_ghost_record_count] ,[min_record_size_in_bytes] ,[max_record_size_in_bytes] ,[avg_record_size_in_bytes] ,[forwarded_record_count] ,[compressed_page_count]) SELECT 'id',* FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID('GuidTable'), 1, DEFAULT, DEFAULT ) ; GO TRUNCATE TABLE GuidTable; GO ALTER TABLE GuidTable DROP CONSTRAINT PK_GuidTable ; GO ALTER TABLE GuidTable ADD CONSTRAINT PK_GuidTable PRIMARY KEY (newidguid) ; GO /* Run the test harness */ INSERT INTO [dbo].[IndexStats] ([IndexColumn] ,[database_id] ,[object_id] ,[index_id] ,[partition_number] ,[index_type_desc] ,[alloc_unit_type_desc] ,[index_depth] ,[index_level] ,[avg_fragmentation_in_percent] ,[fragment_count] ,[avg_fragment_size_in_pages] ,[page_count] ,[avg_page_space_used_in_percent] ,[record_count] ,[ghost_record_count] ,[version_ghost_record_count] ,[min_record_size_in_bytes] ,[max_record_size_in_bytes] ,[avg_record_size_in_bytes] ,[forwarded_record_count] ,[compressed_page_count]) SELECT 'newidguid',* FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID('GuidTable'), 1, DEFAULT, DEFAULT ) ; GO TRUNCATE TABLE GuidTable; GO ALTER TABLE GuidTable DROP CONSTRAINT PK_GuidTable ; GO ALTER TABLE GuidTable ADD CONSTRAINT PK_GuidTable PRIMARY KEY (newsequentualidguid) ; GO /* Run the test harness */ INSERT INTO [dbo].[IndexStats] ([IndexColumn] ,[database_id] ,[object_id] ,[index_id] ,[partition_number] ,[index_type_desc] ,[alloc_unit_type_desc] ,[index_depth] ,[index_level] ,[avg_fragmentation_in_percent] ,[fragment_count] ,[avg_fragment_size_in_pages] ,[page_count] ,[avg_page_space_used_in_percent] ,[record_count] ,[ghost_record_count] ,[version_ghost_record_count] ,[min_record_size_in_bytes] ,[max_record_size_in_bytes] ,[avg_record_size_in_bytes] ,[forwarded_record_count] ,[compressed_page_count]) SELECT 'newsequentualidguid',* FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID('GuidTable'), 1, DEFAULT, DEFAULT ) ; GO TRUNCATE TABLE GuidTable; GO ALTER TABLE GuidTable DROP CONSTRAINT PK_GuidTable ; GO ALTER TABLE GuidTable ADD CONSTRAINT PK_GuidTable PRIMARY KEY (dotnetguid) ; GO /* Run the test harness */ INSERT INTO [dbo].[IndexStats] ([IndexColumn] ,[database_id] ,[object_id] ,[index_id] ,[partition_number] ,[index_type_desc] ,[alloc_unit_type_desc] ,[index_depth] ,[index_level] ,[avg_fragmentation_in_percent] ,[fragment_count] ,[avg_fragment_size_in_pages] ,[page_count] ,[avg_page_space_used_in_percent] ,[record_count] ,[ghost_record_count] ,[version_ghost_record_count] ,[min_record_size_in_bytes] ,[max_record_size_in_bytes] ,[avg_record_size_in_bytes] ,[forwarded_record_count] ,[compressed_page_count]) SELECT 'dotnetguid',* FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID('GuidTable'), 1, DEFAULT, DEFAULT ) ; GO TRUNCATE TABLE GuidTable; GO ALTER TABLE GuidTable DROP CONSTRAINT PK_GuidTable ; GO ALTER TABLE GuidTable ADD CONSTRAINT PK_GuidTable PRIMARY KEY (dotnetsequentialguid) ; GO /* Run the test harness */ INSERT INTO [dbo].[IndexStats] ([IndexColumn] ,[database_id] ,[object_id] ,[index_id] ,[partition_number] ,[index_type_desc] ,[alloc_unit_type_desc] ,[index_depth] ,[index_level] ,[avg_fragmentation_in_percent] ,[fragment_count] ,[avg_fragment_size_in_pages] ,[page_count] ,[avg_page_space_used_in_percent] ,[record_count] ,[ghost_record_count] ,[version_ghost_record_count] ,[min_record_size_in_bytes] ,[max_record_size_in_bytes] ,[avg_record_size_in_bytes] ,[forwarded_record_count] ,[compressed_page_count]) SELECT 'dotnetsequentialguid',* FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID('GuidTable'), 1, DEFAULT, DEFAULT ) ; GO TRUNCATE TABLE GuidTable; GO ALTER TABLE GuidTable DROP CONSTRAINT PK_GuidTable ; GO ALTER TABLE GuidTable ADD CONSTRAINT PK_GuidTable PRIMARY KEY (dotnetmodifiedsequentialguid) ; GO /* Run the test harness */ INSERT INTO [dbo].[IndexStats] ([IndexColumn] ,[database_id] ,[object_id] ,[index_id] ,[partition_number] ,[index_type_desc] ,[alloc_unit_type_desc] ,[index_depth] ,[index_level] ,[avg_fragmentation_in_percent] ,[fragment_count] ,[avg_fragment_size_in_pages] ,[page_count] ,[avg_page_space_used_in_percent] ,[record_count] ,[ghost_record_count] ,[version_ghost_record_count] ,[min_record_size_in_bytes] ,[max_record_size_in_bytes] ,[avg_record_size_in_bytes] ,[forwarded_record_count] ,[compressed_page_count]) SELECT 'dotnetmodifiedsequentialguid',* FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID('GuidTable'), 1, DEFAULT, DEFAULT ) ; GO SELECT [IndexColumn] ,[avg_fragmentation_in_percent] ,[fragment_count] ,[avg_fragment_size_in_pages] ,[page_count] ,[avg_page_space_used_in_percent] ,[record_count] FROM [dbo].[IndexStats] WHERE index_level = 0 GO