75 lines
2.2 KiB
Transact-SQL
75 lines
2.2 KiB
Transact-SQL
USE [HCITools]
|
|
GO
|
|
|
|
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[mon_Aggregate_Stats_Index]') AND type in (N'P', N'PC'))
|
|
DROP PROCEDURE [dbo].[mon_Aggregate_Stats_Index]
|
|
GO
|
|
|
|
USE [HCITools]
|
|
GO
|
|
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
|
|
|
|
CREATE PROCEDURE [dbo].[mon_Aggregate_Stats_Index]
|
|
AS
|
|
/*=============================================================================
|
|
|
|
Explication du traitement realise par la SP
|
|
-------------------------------------------
|
|
La SP va aggreger l'ensemble des statistiques des index contenues dans la table All_Stats_index
|
|
|
|
Contexte d'utilisation
|
|
----------------------
|
|
Appelé depuis le job D92090 - Aggregate Stats Index
|
|
|
|
Creation : 03.08.15 / FLA
|
|
|
|
Modifications : 18.11.2015 / FLA : Ajout d'un try/catch dans le cas où les bases sont indisponibles et éviter ainsi de ne pas récuperer les stats des bases suivantes
|
|
04.10.2017 / FLA : Ajout de la gestion des environnements
|
|
|
|
=============================================================================*/
|
|
|
|
set nocount on;
|
|
|
|
|
|
/*------------------- Declaration des variables --------------------*/
|
|
|
|
|
|
/*------------ Affectation des parametres aux variables ------------*/
|
|
|
|
IF EXISTS (SELECT type FROM master.cfg.InstanceContext WHERE type = 'PROD')
|
|
BEGIN
|
|
|
|
/*-------------------------- Traitement ---------------------------*/
|
|
BEGIN TRY
|
|
|
|
truncate table Aggregate_Stats_index
|
|
|
|
insert into Aggregate_Stats_index
|
|
SELECT SI_ServerName,SI_schemaname,SI_databasename,SI_tablename,SI_indexname, SI_indextype, SUM(isnull(SI_user_seeks,0)) NbSeeks, SUM(isnull(SI_user_scans,0)) NbScans, SUM(isnull(SI_user_lookups,0)) NbLookups, SUM(isnull(SI_user_updates,0)) NbUpdates, MIN(SI_updatedate) UpdateDate, MAX(SI_restartdate) restartdate
|
|
FROM dbo.All_Stats_index
|
|
WHERE SI_deletedate is null
|
|
GROUP BY SI_ServerName,SI_schemaname,SI_databasename,SI_tablename, SI_indexname, SI_indextype
|
|
|
|
/*---------------------- Traitement des erreurs ----------------------*/
|
|
END TRY
|
|
BEGIN CATCH
|
|
|
|
/* Traitement des erreurs (avec RaiseError) */
|
|
EXEC dbo.get_Error_Info @in_RaiseError = 1
|
|
|
|
END CATCH
|
|
|
|
END
|
|
|
|
|
|
GO
|
|
|
|
|