[Solved] SQL Server fragmentation


1.create a table with some GUID as primary Key
2.do inserts and check fragmentation
3.Rebuild check Fragmentation

you also can do search like below for more SO Examples

sql server fragmentation site *.stackexchange.com

simple Demo:

create table test1
(
id varchar(255) primary key default newid()
)

insert into test1
default values
go 100


--check fragmentation
select avg_fragmentation_in_percent, avg_fragment_size_in_pages, fragment_count, avg_page_space_used_in_percent
from sys.dm_db_index_physical_stats (DB_ID(), object_id('test1'), NULL, NULL, 'DETAILED')

--rebuild index
ALTER INDEX ALL ON test1
REBUILD  

--check fragmentation
select avg_fragmentation_in_percent, avg_fragment_size_in_pages, fragment_count, avg_page_space_used_in_percent
from sys.dm_db_index_physical_stats (DB_ID(), object_id('test1'), NULL, NULL, 'DETAILED')

0

solved SQL Server fragmentation