Skip to content

Commit 4d0e8b9

Browse files
authored
Create calculate-fragmentation_percent.sql
1 parent 438526a commit 4d0e8b9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
USE University;
2+
GO
3+
SELECT t.name AS Table_name,
4+
i.name AS Index_name,
5+
ps.avg_fragmentation_in_percent
6+
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'LIMITED') AS ps
7+
INNER JOIN sys.indexes i
8+
ON ps.object_id = i.object_id AND ps.index_id = i.index_id
9+
INNER JOIN sys.tables t
10+
ON i.object_id = t.object_id
11+
WHERE i.type_desc IN ('CLUSTERED', 'NONCLUSTERED') AND ps.database_id = DB_ID()
12+
ORDER BY ps.avg_fragmentation_in_percent DESC;

0 commit comments

Comments
 (0)