Collections:
What Causes Index Fragmentation in SQL Server
What Causes Index Fragmentation in SQL Server?
✍: FYIcenter.com
Index fragmentation is usually caused by deleting of existing rows or updating existing values of the indexed column. Inserting new rows should not cause any index fragmentation.
This tutorial exercise shows you how update statements of 50000 rows on the table "fyi_link_indexed" with 100000 rows caused the index fragmented 84%:
USE FyiCenterData;
GO
SELECT COUNT(*) FROM fyi_links_indexed;
GO
100000
SELECT i.index_id, i.name, s.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (
DB_ID(N'FyiCenterData'),
OBJECT_ID(N'fyi_links_indexed'),
DEFAULT, DEFAULT, DEFAULT) s, sys.indexes i
WHERE s.object_id = i.object_id
AND s.index_id = i.index_id;
GO
0 NULL 0.574712643678161
2 fyi_links_url 0
3 fyi_links_counts 0
UPDATE fyi_links_indexed SET url = REVERSE(url)
WHERE id <=50000;
GO
(50000 row(s) affected)
SELECT i.index_id, i.name, s.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (
DB_ID(N'FyiCenterData'),
OBJECT_ID(N'fyi_links_indexed'),
DEFAULT, DEFAULT, DEFAULT) s, sys.indexes i
WHERE s.object_id = i.object_id
AND s.index_id = i.index_id;
GO
0 NULL 0.574712643678161
2 fyi_links_url 84.053862508859
3 fyi_links_counts 0.448430493273543
Note that only the index on "url" fragmented. Index on "counts" did not affected, because the update statement only touched the "url" column.
⇒ Defragmenting Table Indexes in SQL Server
⇐ What Is Index Fragmentation in SQL Server
2016-11-08, 2851🔥, 0💬
Popular Posts:
How To Install PHP on Windows in MySQL? The best way to download and install PHP on Windows systems ...
How To Provide Default Values to Function Parameters in SQL Server Transact-SQL? If you add a parame...
Why I Can Not Enter 0.001 Second in DATETIME values in SQL Server Transact-SQL? If you enter millise...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...
How REAL and FLOAT Literal Values Are Rounded in SQL Server Transact-SQL? By definition, FLOAT(n) sh...