1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
TOTO
USE [TOTO];
INSERT INTO #tempcursor
SELECT 'USE [TOTO]; ALTER index ['+i.name+'] ON ['+TABLE_SCHEMA+'].['+OBJECT_NAME(ips.object_id)+'] REBUILD;' as valueReturn
FROM sys.dm_db_index_physical_stats(5, default, default, default, default) ips
INNER JOIN sys.indexes i
ON ips.index_id = i.index_id AND ips.object_id = i.object_id
INNER JOIN INFORMATION_SCHEMA.TABLES
ON OBJECT_NAME(ips.object_id) = TABLE_NAME
WHERE ips.object_id > 99 AND ips.avg_fragmentation_in_percent >= 30 AND
ips.index_id > 0 AND ips.page_count > 0;
TATA
USE [TATA];
INSERT INTO #tempcursor
SELECT 'USE [TATA]; ALTER index ['+i.name+'] ON ['+TABLE_SCHEMA+'].['+OBJECT_NAME(ips.object_id)+'] REBUILD;' as valueReturn
FROM sys.dm_db_index_physical_stats(6, default, default, default, default) ips
INNER JOIN sys.indexes i
ON ips.index_id = i.index_id AND ips.object_id = i.object_id
INNER JOIN INFORMATION_SCHEMA.TABLES
ON OBJECT_NAME(ips.object_id) = TABLE_NAME
WHERE ips.object_id > 99 AND ips.avg_fragmentation_in_percent >= 30 AND
ips.index_id > 0 AND ips.page_count > 0;
TITI
USE [TITI];
INSERT INTO #tempcursor
SELECT 'USE [TITI]; ALTER index ['+i.name+'] ON ['+TABLE_SCHEMA+'].['+OBJECT_NAME(ips.object_id)+'] REBUILD;' as valueReturn
FROM sys.dm_db_index_physical_stats(8, default, default, default, default) ips
INNER JOIN sys.indexes i
ON ips.index_id = i.index_id AND ips.object_id = i.object_id
INNER JOIN INFORMATION_SCHEMA.TABLES
ON OBJECT_NAME(ips.object_id) = TABLE_NAME
WHERE ips.object_id > 99 AND ips.avg_fragmentation_in_percent >= 30 AND
ips.index_id > 0 AND ips.page_count > 0; |
Partager