I have one problem about fragmentation. I had one table structure as below
USE [FragmenTests]
GO
/****** Object: Table [dbo].[Test_Fragmentation] Script Date: 4/12/2021 2:54:16 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].Test_Fragmentation ON [SNAPSHOT]
GO
USE [FragmenTests]
GO
/****** Object: Index [IX_DEBTS_ID] Script Date: 4/12/2021 2:56:33 PM ******/
CREATE UNIQUE CLUSTERED INDEX [IX_DEBTS_ID] ON [dbo].[Test_Fragmentation]
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [SNAPSHOT]
GO
SET ANSI_PADDING ON
GO
/****** Object: Index [IX_DEBTS_SUBID] Script Date: 4/12/2021 2:56:33 PM ******/
CREATE NONCLUSTERED INDEX [IX_DEBTS_SUBID] ON [dbo].[Test_Fragmentation]
(
[SubscriberId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [SNAPSHOTIDX]
GO
I must added random data. That is why I create script as follow
declare @n bigint =4305444830
while @n<9305444830
begin
set @n=@n+1
insert into [dbo].[Test_Fragmentation] ([ID],[SubscriberId])
select @n,Cast(ABS(CAST(CHECKSUM(NEWID()) AS bigint) *Cast(100 as bigint)) as nvarchar(20))
end
After this index fragmentation result as follow
My answer is : How to avoid of fragmentation with inserting random data. I try to change fill factor and data type. But it doesn't help me.