This commit is contained in:
Thierry Schork
2025-09-16 08:26:19 +02:00
parent b0e4d245eb
commit de97031b1e
5 changed files with 317 additions and 4 deletions

View File

@@ -21,7 +21,7 @@ SELECT t.name AS TableName,
WHERE i.object_id > 255
-- AND i.index_id IN ( 0, 1 ) --0=heap, 1= clustered
AND t.name NOT LIKE 'dt%'
AND t.name LIKE 'archive[_]%'
AND t.name LIKE '%'
AND [t].[is_ms_shipped] = 0
AND i.object_id > 255
GROUP BY t.name,

View File

@@ -40,6 +40,8 @@ WHERE type IN (0,1);';
SELECT *
FROM #FileSize
*/
--the free space in MB that should be present in the files after shrinking
DECLARE @limit INT = 512;
SELECT
d.[name] AS dbName
@@ -65,18 +67,20 @@ GO
' AS reorganizeData
,'USE '+d.name+';
IF 1024 < '+CAST(CAST(f.size * 8.0 / 1024 AS DECIMAL(18,2)) AS VARCHAR(15))+' --file is above 1Go
AND 95 > '+CAST(CAST((fs.[CurrentSizeMB] - fs.[FreeSpaceMB]) * 100 / (CAST(f.size * 8.0 / 1024 AS DECIMAL(18,2))) AS DECIMAL(6,2))AS VARCHAR(15))+' --and usage below 95%
IF '+CAST(@limit AS VARCHAR(20))+' < '+CAST(CAST(f.size * 8.0 / 1024 AS DECIMAL(18,2)) AS VARCHAR(15))+' --file is above requested free space
--AND 95 > '+CAST(CAST((fs.[CurrentSizeMB] - fs.[FreeSpaceMB]) * 100 / (CAST(f.size * 8.0 / 1024 AS DECIMAL(18,2))) AS DECIMAL(6,2))AS VARCHAR(15))+' --and usage below 95%
AND '+CAST(fs.[FreeSpaceMB] AS VARCHAR(20))+' > '+CAST(@limit AS VARCHAR(20))+' --free space is over the requested limit
AND 0 < '+CAST(CAST(fs.[CurrentSizeMB] - fs.[FreeSpaceMB] AS DECIMAL(18,2))AS VARCHAR(15))+' --and data are present
BEGIN
--print ''Reorganize '+d.name+'.'+f.name+' ''
RAISERROR(''Reorganize '+d.name+'.'+f.name+' '',0,0) WITH NOWAIT
DBCC SHRINKFILE (N'''+f.[name]+''' , '+CAST(CAST(fs.[CurrentSizeMB] - fs.[FreeSpaceMB] + 1024 AS DECIMAL(18,0)) AS VARCHAR(15))+');
DBCC SHRINKFILE (N'''+f.[name]+''' , '+CAST(CAST(fs.[CurrentSizeMB] - fs.[FreeSpaceMB] + @limit AS DECIMAL(18,0)) AS VARCHAR(15))+');
RAISERROR(''Done'',0,0) WITH NOWAIT
END
GO
' AS auto_action
--,fs.[CurrentSizeMB] - fs.[FreeSpaceMB] AS unused_space_mb
FROM sys.master_files F
JOIN sys.databases d ON d.[database_id] = f.[database_id]
JOIN [#dbs] [d2] ON d2.[database_name] = d.[name]

View File

@@ -0,0 +1,118 @@
/*
15.09.2025, TSC
*/
USE [HciLogin]
IF INDEXPROPERTY(OBJECT_ID('UserAddress'), 'NC_IX_UserAddress__User_FK' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_UserAddress__User_FK ON [HciLogin].[dbo].[UserAddress] ([User_FK]) INCLUDE ([UserAddressType_FK], [AdditionalLine1], [Street], [Zip], [City], [Country])
PRINT 'created NC_IX_UserAddress__User_FK'
END
IF INDEXPROPERTY(OBJECT_ID('UserCommunication'), 'NC_IX_UserCommunication__User_FK' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_UserCommunication__User_FK ON [HciLogin].[dbo].[UserCommunication] ([User_FK]) INCLUDE ([UserCommunicationType_FK], [Communication])
PRINT 'created NC_IX_UserCommunication__User_FK'
END
USE [SwissRxLogin2]
IF INDEXPROPERTY(OBJECT_ID('AuthorizationCode'), 'NC_IX_AuthorizationCode__AuthorizationCodeHash' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_AuthorizationCode__AuthorizationCodeHash ON [SwissRxLogin2].[dbo].[AuthorizationCode] ([AuthorizationCodeHash])
PRINT 'created NC_IX_AuthorizationCode__AuthorizationCodeHash'
END
USE [MyProducts]
IF INDEXPROPERTY(OBJECT_ID('ORD_OrderProduct'), 'NC_IX_ORD_OrderProduct__Order_FK' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_ORD_OrderProduct__Order_FK ON [MyProducts].[dbo].[ORD_OrderProduct] ([Order_FK]) INCLUDE ([CoProductCategoryCode_EXT], [ProductNr], [ForFree], [DiscountSameFI], [ProductFamily], [SalesQty], [UnitPrice], [Discount], [Lifecycle], [LifecycleDate], [Db_Status], [Db_InsDt], [Db_InsUser], [App_InsUser], [Db_UpdDt], [Db_UpdUser], [App_UpdUser], [Db_Timestamp])
PRINT 'created NC_IX_ORD_OrderProduct__Order_FK'
END
IF INDEXPROPERTY(OBJECT_ID('ORD_OrderProduct'), 'NC_IX_ORD_OrderProduct__Db_Status' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_ORD_OrderProduct__Db_Status ON [MyProducts].[dbo].[ORD_OrderProduct] ([Db_Status]) INCLUDE ([Order_FK], [CoProductCategoryCode_EXT], [ProductNr], [ProductFamily], [SalesQty], [UnitPrice], [Discount], [Lifecycle])
PRINT 'created NC_IX_ORD_OrderProduct__Db_Status'
END
IF INDEXPROPERTY(OBJECT_ID('PMS_ProductMessage'), 'NC_IX_PMS_ProductMessage__CoProductMessageType_FK_PreviewID_Db_Status' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_PMS_ProductMessage__CoProductMessageType_FK_PreviewID_Db_Status ON [MyProducts].[dbo].[PMS_ProductMessage] ([CoProductMessageType_FK], [PreViewId], [Db_Status])
PRINT 'created NC_IX_PMS_ProductMessage__CoProductMessageType_FK_PreviewID_Db_Status'
END
IF INDEXPROPERTY(OBJECT_ID('ORD_Order'), 'NC_IX_ORD_Order__OrderContractTimePeriod_FK' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_ORD_Order__OrderContractTimePeriod_FK ON [MyProducts].[dbo].[ORD_Order] ([OrderContractTimePeriod_FK]) INCLUDE ([CoOrderStatus_FK], [CoOrderType_FK], [CompanyPtNr], [Title], [TotalCost], [CheckedOutBy], [PurchaseOrderNr], [InvoiceReference], [MaintenanceDateUpload], [Db_Status], [Db_InsDt], [App_InsUser], [Db_UpdDt], [App_UpdUser])
PRINT 'created NC_IX_ORD_Order__OrderContractTimePeriod_FK'
END
USE [CompendiumPortal]
IF INDEXPROPERTY(OBJECT_ID('MON_MonSubVer_MonSection'), 'NC_IX_MON_MonSubVer_MonSection__MonSubVer_FK' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_MON_MonSubVer_MonSection__MonSubVer_FK ON [CompendiumPortal].[dbo].[MON_MonSubVer_MonSection] ([MonSubVer_FK]) INCLUDE ([MonSection_FK], [Db_Status], [Db_InsDt], [Db_UpdDt], [Db_Timestamp])
PRINT 'created NC_IX_MON_MonSubVer_MonSection__MonSubVer_FK'
END
IF INDEXPROPERTY(OBJECT_ID('MON_MonSection_Picture'), 'NC_IX_MON_MonSection_Picture__Picture_FK' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_MON_MonSection_Picture__Picture_FK ON [CompendiumPortal].[dbo].[MON_MonSection_Picture] ([Picture_FK]) INCLUDE ([MonSection_FK], [Sort], [Db_Status], [Db_InsDt], [Db_UpdDt], [Db_Timestamp])
PRINT 'created NC_IX_MON_MonSection_Picture__Picture_FK'
END
USE [SwissIndex_Products_Work]
IF INDEXPROPERTY(OBJECT_ID('ARTICLES'), 'NC_IX_ARTICLES__ArtDel' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_ARTICLES__ArtDel ON [SwissIndex_Products_Work].[dbo].[ARTICLES] ([ArtDel]) INCLUDE ([ArtNo], [ArtIndexCode], [ArtDT], [ArtXML])
PRINT 'created NC_IX_ARTICLES__ArtDel'
END
IF INDEXPROPERTY(OBJECT_ID('ARTICLEWHOLESALERS'), 'NC_IX_ARTICLEWHOLESALERS__AwhIndexCode' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_ARTICLEWHOLESALERS__AwhIndexCode ON [SwissIndex_Products_Work].[dbo].[ARTICLEWHOLESALERS] ([AwhIndexCode]) INCLUDE ([AwhNo], [AwhDT], [AwhXML])
PRINT 'created NC_IX_ARTICLEWHOLESALERS__AwhIndexCode'
END
USE [Index_Viewer]
IF INDEXPROPERTY(OBJECT_ID('PRODUCT___PRD'), 'NC_IX_PRODUCT___PRD__BatchType_Trade_Del' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_PRODUCT___PRD__BatchType_Trade_Del ON [Index_Viewer].[dbo].[PRODUCT___PRD] ([BatchType], [TRADE], [DEL]) INCLUDE ([PRDNO], [DSCRD], [QAP])
PRINT 'created NC_IX_PRODUCT___PRD__BatchType_Trade_Del'
END
IF INDEXPROPERTY(OBJECT_ID('ARTICLE___ARTINS'), 'NC_IX_ARTICLE___ARTINS__Nincd' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_ARTICLE___ARTINS__Nincd ON [Index_Viewer].[dbo].[ARTICLE___ARTINS] ([NINCD]) INCLUDE ([XmlIndex], [BatchType], [ART_Id])
PRINT 'created NC_IX_ARTICLE___ARTINS__Nincd'
--DROP INDEX [NC_IX_ARTICLE__Nincd] ON [ARTICLE___ARTINS]
END
-- IX_ARTICLE_ART__BType_DEL_wIncludes
IF INDEXPROPERTY(OBJECT_ID('dbo.ARTICLE___ART'), 'IX_ARTICLE_ART__BType_DEL_wIncludes' , 'IndexID' ) IS NOT NULL BEGIN;
DROP INDEX dbo.ARTICLE___ART.IX_ARTICLE_ART__BType_DEL_wIncludes;
END;
IF INDEXPROPERTY(OBJECT_ID('dbo.ARTICLE___ART'), 'IX_ARTICLE_ART__BType_DEL_wIncludes' , 'IndexID' ) IS NULL BEGIN;
CREATE INDEX IX_ARTICLE_ART__BType_DEL_wIncludes ON dbo.ARTICLE___ART(BatchType, DEL) INCLUDE(ART_Id, DT, PHAR, XmlIndex,[PHARMACODE], [QTY], [DSCRD], [NOPCS]);
END;
USE [JOB]
IF INDEXPROPERTY(OBJECT_ID('JOB_STATE'), 'NC_IX_JOB_STATE__State' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_JOB_STATE__State ON [JOB].[dbo].[JOB_STATE] ([STATE]) INCLUDE ([JOBNAME])
PRINT 'created NC_IX_JOB_STATE__State'
END

View File

@@ -0,0 +1,182 @@
/*
Missing Index Details from Regressed Queries [RedApp]
The Query Processor estimates that implementing the following index could improve the query cost by 22.5659%.
*/
USE [RedApp]
GO
IF INDEXPROPERTY(OBJECT_ID('IND_MeddraLowLevelTermDes'), 'NC_IX_IND_MeddraLowLevelTermDes__term_FK__Lang' , 'IndexID' ) IS NULL
BEGIN;
CREATE NONCLUSTERED INDEX NC_IX_IND_MeddraLowLevelTermDes__term_FK__Lang
ON [dbo].[IND_MeddraLowLevelTermDes] ([MeddraLowLevelTerm_FK],[Lang])
INCLUDE ([Descr]);
PRINT 'created NC_IX_IND_MeddraLowLevelTermDes__term_FK__Lang'
END
GO
IF INDEXPROPERTY(OBJECT_ID('WF_BmOrder'), 'NC_IX_WF_BmOrder__db_status' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_WF_BmOrder__db_status ON [RedApp].[dbo].[WF_BmOrder] ([Db_Status]);
PRINT 'created NC_IX_WF_BmOrder__db_status'
END
IF INDEXPROPERTY(OBJECT_ID('ART_ArtLnk'), 'NC_IX_ART_ArtLnk__CoLnk_FK' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_ART_ArtLnk__CoLnk_FK ON [RedApp].[dbo].[ART_ArtLnk] ([CoLnk_FK], [WithdrawnDate], [FromDate], [ToDate], [Db_Status]) INCLUDE ([Art_FK], [Linked_Art_FK]);
PRINT 'created NC_IX_ART_ArtLnk__CoLnk_FK'
END
IF INDEXPROPERTY(OBJECT_ID('Q_ART_ArtSta'), 'NC_IX_Q_ART_ArtSta__Art_FK' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_Q_ART_ArtSta__Art_FK ON [RedApp].[dbo].[Q_ART_ArtSta] ([Art_FK], [WithdrawnDate], [FromDate], [Db_Status]);
PRINT 'created NC_IX_Q_ART_ArtSta__Art_FK'
END
IF INDEXPROPERTY(OBJECT_ID('WF_BmOrder'), 'NC_IX_WF_BmOrder__Editor' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_WF_BmOrder__Editor ON [RedApp].[dbo].[WF_BmOrder] ([Editor]) INCLUDE ([CoOrderType_FK], [Db_Status])
PRINT 'created NC_IX_WF_BmOrder__Editor'
END
IF INDEXPROPERTY(OBJECT_ID('PAC_PacStructure'), 'NC_IX_PAC_PacStructure__Descendant_Pac_FK' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_PAC_PacStructure__Descendant_Pac_FK ON [RedApp].[dbo].[PAC_PacStructure] ([Descendant_Pac_FK], [LevelPath], [Db_Status]);
PRINT 'created NC_IX_PAC_PacStructure__Descendant_Pac_FK'
END
IF INDEXPROPERTY(OBJECT_ID('PRD_PrdAdrInducer'), 'NC_IX_PRD_PrdAdrInducer__Prd_FK' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_PRD_PrdAdrInducer__Prd_FK ON [RedApp].[dbo].[PRD_PrdAdrInducer] ([Prd_FK], [Db_Status]);
PRINT 'created NC_IX_PRD_PrdAdrInducer__Prd_FK'
END
IF INDEXPROPERTY(OBJECT_ID('Q_WF_TaskRemark'), 'NC_IX_Q_WF_TaskRemark__TcTaskRemarkType_FK' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_Q_WF_TaskRemark__TcTaskRemarkType_FK ON [RedApp].[dbo].[Q_WF_TaskRemark] ([TcTaskRemarkType_FK], [DropDt]) INCLUDE ([Task_FK]);
PRINT 'created NC_IX_Q_WF_TaskRemark__TcTaskRemarkType_FK'
END
-- IX_ART_Art__Stat__wIncludes
IF INDEXPROPERTY(OBJECT_ID('dbo.ART_Art'), 'IX_ART_Art__Stat__wIncludes' , 'IndexID' ) IS NOT NULL BEGIN;
DROP INDEX dbo.ART_Art.IX_ART_Art__Stat__wIncludes;
PRINT 'drop IX_ART_Art__Stat__wIncludes'
END;
IF INDEXPROPERTY(OBJECT_ID('dbo.ART_Art'), 'IX_ART_Art__Stat__wIncludes' , 'IndexID' ) IS NULL BEGIN;
CREATE INDEX IX_ART_Art__Stat__wIncludes ON [RedApp].[dbo].[ART_Art] ([Db_Status]) INCLUDE ([Prd_FK], [CoCat_FK], [Pharmacode], [IsOfficial], [PubScope_BIN], [CreateDt], [LastModifiedDt], [Db_InsDt], [Db_InsUser], [Db_UpdDt], [Db_UpdUser], [Db_Timestamp]);;
PRINT 'created IX_ART_Art__Stat__wIncludes';
END;
GO
IF INDEXPROPERTY(OBJECT_ID('Ia_Sb'), 'NC_IX_Ia_Sb__PinPt' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_Ia_Sb__PinPt ON [RedApp].[dbo].[Ia_Sb] ([PinPt]) INCLUDE ([IaId], [SbId], [IaCoRatingId]);
PRINT 'created NC_IX_Ia_Sb__PinPt'
END
IF INDEXPROPERTY(OBJECT_ID('BM_BmCoding'), 'NC_IX_BM_BmCoding__MeddraLowLevelTerm_FK_IsIndication' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_BM_BmCoding__MeddraLowLevelTerm_FK_IsIndication ON [RedApp].[dbo].[BM_BmCoding] ([MeddraLowLevelTerm_FK], [IsIndication]) INCLUDE ([BmRev_FK]);
PRINT 'created NC_IX_BM_BmCoding__MeddraLowLevelTerm_FK_IsIndication'
END
IF INDEXPROPERTY(OBJECT_ID('PRD_PrdDeclarationOfConformity'), 'NC_IX_PRD_PrdDeclarationOfConformity__WithdrawnDate_ExpirationDate' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_PRD_PrdDeclarationOfConformity__WithdrawnDate_ExpirationDate ON [RedApp].[dbo].[PRD_PrdDeclarationOfConformity] ([WithdrawnDate], [ExpirationDate], [FromDate], [Db_Status]) INCLUDE ([Prd_FK], [RevisionDate], [EuFlag]);
PRINT 'created NC_IX_PRD_PrdDeclarationOfConformity__WithdrawnDate_ExpirationDate'
END
IF INDEXPROPERTY(OBJECT_ID('SbLink'), 'NC_IX_SbLink__LinkTypeId_IsDeleted' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_SbLink__LinkTypeId_IsDeleted ON [RedApp].[dbo].[SbLink] ([LinkTypeId], [IsDeleted]) INCLUDE ([SbId], [LinkedSbId]);
PRINT 'created NC_IX_SbLink__LinkTypeId_IsDeleted'
END
-- NC_IX_PAC_PacStructure__Descendant_Pac_FK
IF INDEXPROPERTY(OBJECT_ID('dbo.PAC_PacStructure'), 'NC_IX_PAC_PacStructure__Descendant_Pac_FK' , 'IndexID' ) IS NOT NULL BEGIN;
DROP INDEX dbo.PAC_PacStructure.NC_IX_PAC_PacStructure__Descendant_Pac_FK;
PRINT 'drop NC_IX_PAC_PacStructure__Descendant_Pac_FK'
END;
IF INDEXPROPERTY(OBJECT_ID('PAC_PacStructure'), 'NC_IX_PAC_PacStructure__Descendant_Pac_FK' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_PAC_PacStructure__Descendant_Pac_FK ON [RedApp].[dbo].[PAC_PacStructure] ([Descendant_Pac_FK], [Db_Status])
INCLUDE([LevelPath]);
PRINT 'created NC_IX_PAC_PacStructure__Descendant_Pac_FK'
END
IF INDEXPROPERTY(OBJECT_ID('BM_BmVerContent'), 'NC_IX_BM_BmVerContent__Db_Status' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_BM_BmVerContent__Db_Status ON [RedApp].[dbo].[BM_BmVerContent] ([Db_Status]) INCLUDE ([BmVer_FK], [BmContent_FK]);
PRINT 'created NC_IX_BM_BmVerContent__Db_Status'
END
IF INDEXPROPERTY(OBJECT_ID('PRD_PrdSta'), 'NC_IX_PRD_PrdSta__FromDate' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_PRD_PrdSta__FromDate ON [RedApp].[dbo].[PRD_PrdSta] ([FromDate]) INCLUDE ([CoSta_FK]);
PRINT 'created NC_IX_PRD_PrdSta__FromDate'
END
IF INDEXPROPERTY(OBJECT_ID('IND_MeddraPreferredTermDes'), 'NC_IX_IND_MeddraPreferredTermDes__MeddraPreferredTerm_FK_Lang' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_IND_MeddraPreferredTermDes__MeddraPreferredTerm_FK_Lang ON [RedApp].[dbo].[IND_MeddraPreferredTermDes] ([MeddraPreferredTerm_FK], [Lang]) INCLUDE ([Descr]);
PRINT 'created NC_IX_IND_MeddraPreferredTermDes__MeddraPreferredTerm_FK_Lang'
END
IF INDEXPROPERTY(OBJECT_ID('CM_Cm'), 'NC_IX_CM_Cm__Db_Status' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_CM_Cm__Db_Status ON [RedApp].[dbo].[CM_Cm] ([Db_Status]) INCLUDE ([CMNr_Ext], [CMRevNr_Ext]);
PRINT 'created NC_IX_CM_Cm__Db_Status'
END
-- IX_Sb__IsSwiss_IsDel
IF INDEXPROPERTY(OBJECT_ID('dbo.Sb'), 'IX_Sb__IsSwiss_IsDel' , 'IndexID' ) IS NOT NULL BEGIN;
DROP INDEX dbo.Sb.IX_Sb__IsSwiss_IsDel;
END;
IF INDEXPROPERTY(OBJECT_ID('Sb'), 'IX_Sb__IsSwiss_IsDel' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX IX_Sb__IsSwiss_IsDel ON [RedApp].[dbo].[Sb] ([IsSwissSb], [IsDeleted]) INCLUDE ([SbNr]);
PRINT 'created IX_Sb__IsSwiss_IsDel'
END
IF INDEXPROPERTY(OBJECT_ID('CM_CmPrd'), 'NC_IX_CM_CmPrd__Db_Status' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_CM_CmPrd__Db_Status ON [RedApp].[dbo].[CM_CmPrd] ([Db_Status]) INCLUDE ([Cm_FK], [Prd_FK], [ToDate]);
PRINT 'created NC_IX_CM_CmPrd__Db_Status'
END
IF INDEXPROPERTY(OBJECT_ID('PRD_AtcDes'), 'NC_IX_PRD_AtcDes__Lang_Db_Status' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_PRD_AtcDes__Lang_Db_Status ON [RedApp].[dbo].[PRD_AtcDes] ([Lang], [Db_Status]) INCLUDE ([Atc_FK], [Descr]);
PRINT 'created NC_IX_PRD_AtcDes__Lang_Db_Status'
END
IF INDEXPROPERTY(OBJECT_ID('GRP_GrpDes'), 'NC_IX_GRP_GrpDes__Lang' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_GRP_GrpDes__Lang ON [RedApp].[dbo].[GRP_GrpDes] ([Lang]) INCLUDE ([Grp_FK], [Descr]);
PRINT 'created NC_IX_GRP_GrpDes__Lang'
END
IF INDEXPROPERTY(OBJECT_ID('CPT_CptCalcCompositionSb'), 'NC_IX_CPT_CptCalcCompositionSb__Sb_Fk_Db_Status' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_CPT_CptCalcCompositionSb__Sb_Fk_Db_Status ON [RedApp].[dbo].[CPT_CptCalcCompositionSb] ([Sb_FK], [Db_Status]);
PRINT 'created NC_IX_CPT_CptCalcCompositionSb__Sb_Fk_Db_Status'
END
IF INDEXPROPERTY(OBJECT_ID('BM_Dos'), 'NC_IX_BM_Dos__BmRev_FK_Db_Status' , 'IndexID' ) IS NULL
BEGIN;
CREATE INDEX NC_IX_BM_Dos__BmRev_FK_Db_Status ON [RedApp].[dbo].[BM_Dos] ([BmRev_FK], [Db_Status]);
PRINT 'created NC_IX_BM_Dos__BmRev_FK_Db_Status'
END
IF INDEXPROPERTY(OBJECT_ID('CDS_CdsDose'), 'NC_IX_CDS_CdsDose__Cds_FK_Db_Status' , 'IndexID' ) IS NULL
BEGIN
CREATE INDEX NC_IX_CDS_CdsDose__Cds_FK_Db_Status ON [RedApp].[dbo].[CDS_CdsDose] ([Cds_FK], [Db_Status]);
PRINT 'created NC_IX_CDS_CdsDose__Cds_FK_Db_Status'
END

9
wa.sql Normal file
View File

@@ -0,0 +1,9 @@
EXEC master.dbo.sp_whoisactive
    @get_additional_info=0,@get_task_info=1, @output_column_list='[percent_complete][status][database_name][dd%][session_id][blocking_session_id][blocked_session_count][sql_text][sql_command][query_plan][login_name][wait_info][host_name][tasks][tran_log%][cpu%][temp%][block%][reads%][writes%][context%][physical%][locks][%]', @format_output=1
    ,@get_plans=0
    ,@get_outer_command=1
    ,@get_locks = 0
    ,@find_block_leaders = 1
    ,@sort_order = '[blocked_session_count] DESC,[session_id] ASC, [dd hh:mm:ss.mss] DESC';
GO