notebook/IT/SQL/SCRIPTS SQL QSA ORSYS/Demo index et stats.sql
2020-11-26 18:38:25 +01:00

28 lines
913 B
SQL

-- diagnostic des index fragmentés
SELECT * FROM sys.dm_db_index_physical_stats(NULL, NULL, NULL, NULL, NULL)
WHERE avg_fragmentation_in_percent > 10
AND page_count>64
-- ALTER INDEX .... REORGANIZE --> pas bloquant mais pas top
-- ALTER INDEX .... REBUILD --> bloquant mais top (peut être non bloquant si ed. Enterprise et mode ONLINE)
-- diagnostic des index inutilisés
-- !!!!!!!!!!!!!!!!!!!!!!!!! ATTENTION : ne pas utiliser si moins de 30 jours de fonctionnement CONTINU du SGBDR
SELECT sqlserver_start_time FROM sys.dm_os_sys_info
SELECT *
FROM sys.dm_db_index_usage_stats
WHERE index_id > 1
ORDER BY user_seeks, user_lookups, user_scans, user_updates DESC
-- recalcul des statistiques
SELECT *
FROM sys.stats AS s
CROSS APPLY sys.dm_db_stats_properties(s.object_id, s.stats_id)
WHERE modification_counter > rows / 10
UPDATE STATISTICS .... WITH FULLSCAN