Collections:
"ALTER INDEX ... REBUILD" - Defragmenting Indexes in SQL Server
How To Rebuild Indexes with ALTER INDEX ... REBUILD in SQL Server?
✍: FYIcenter.com
When an index is defragmented to a large percentage, like > 30%, you can use the "ALTER INDEX ... REBUILD" statement to rebuild the index. Here is a tutorial exercise on rebuilding indexes:
USE FyiCenterData;
GO
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 85.0142045454545
3 fyi_links_counts 0.448430493273543
ALTER INDEX fyi_links_url ON fyi_links_indexed REBUILD;
GO
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.448430493273543
Rebuilding an index brings the fragmentation level to 0% in this case.
⇒ Rebuilding All Indexes on One Table in SQL Server
⇐ "ALTER INDEX ... REORGANIZE" - Defragmenting Indexes in SQL Server
2016-11-08, 2859🔥, 0💬
Popular Posts:
What Is "mysqld" in MySQL? "mysqld" is MySQL server daemon program which runs quietly in background ...
How to connect SQL Server Management Studio Express to SQL Server 2005 Express in SQL Server? Once y...
What Happens to Your Transactions When ERROR 1213 Occurred in MySQL? If your transaction receives th...
Can Binary Strings Be Converted into NUMERIC or FLOAT Data Types in SQL Server Transact-SQL? Can bin...
Where to find answers to frequently asked questions on Managing Security, Login and User in SQL Serv...