﻿-- ==================================================================================================================================
-- T_TANULOCSOPORT
-- ==================================================================================================================================
DROP INDEX IF EXISTS IDX_TANULOCSOPORT_INTEZMENYID_TANEVID_OSZTALYCSOPORTID ON T_TANULOCSOPORT
GO

DROP INDEX IF EXISTS IX_TANULOCSOPORT_TANULOID_BELEPESDATUM_KILEPESDATUM_INTEZMENYID_TANEVID ON T_TANULOCSOPORT
GO

DROP INDEX IF EXISTS IDX_TANULOCSOPORT_INTEZMENYID_OSZTALYCSOPORTID ON T_TANULOCSOPORT
GO

DROP INDEX IF EXISTS IDX_TANULOCSOPORT_INTEZMENYID_TANULOID ON T_TANULOCSOPORT
GO

DROP INDEX IF EXISTS IDX_TANULOCSOPORT_OSZTALYCSOPORTID_TANULOID ON T_TANULOCSOPORT
GO

DROP INDEX IF EXISTS UK_TANULOCSOPORT ON T_TANULOCSOPORT
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_TanuloCsoport_OsztalyCsoportId_TanuloId_IntezmenyId_TanevId') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_TanuloCsoport_OsztalyCsoportId_TanuloId_IntezmenyId_TanevId
    ON dbo.T_TANULOCSOPORT (C_INTEZMENYID, C_TANEVID, C_OSZTALYCSOPORTID, C_TANULOID)
  WHERE C_KILEPESDATUM IS NULL AND TOROLT='F'
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloCsoport_OsztalyCsoportId_TanuloId_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanuloCsoport_OsztalyCsoportId_TanuloId_IntezmenyId_TanevId
    ON T_TANULOCSOPORT (
       C_OSZTALYCSOPORTID
      ,C_TANULOID 
      ,C_INTEZMENYID
      ,C_TANEVID
  ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloCsoport_OsztalyCsoportId_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanuloCsoport_OsztalyCsoportId_IntezmenyId_TanevId
    ON T_TANULOCSOPORT (
       C_OSZTALYCSOPORTID
      ,C_INTEZMENYID
      ,C_TANEVID) 
  INCLUDE (
     C_TANULOID
    ,C_BELEPESDATUM
    ,C_KILEPESDATUM
  )
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloCsoport_TanuloId_IntezmenyId_BelepesDatum_KilepesDatum_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanuloCsoport_TanuloId_IntezmenyId_BelepesDatum_KilepesDatum_TanevId 
    ON T_TANULOCSOPORT (
       C_TANULOID
      ,C_INTEZMENYID
      ,C_BELEPESDATUM
      ,C_KILEPESDATUM
      ,C_TANEVID
    ) 
    INCLUDE (C_OSZTALYCSOPORTID) 
    WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_TANITASIORA
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TANITASIORA_INTEZMENYID_TANEVID_TANTARGYID_OSZTALYCSOPORTID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IDX_TANITASIORA_NAPTARINAPID_TANTARGYID_OSZTALYCSOPORTID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_INTEZMENYID_TANEVID_OSZTALYCSOPORTID_TANTARGYID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_INTEZMENYID_TANEVID_DATUM_TANARID_HELYETTESITOTANARID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_DATUM_INTEZMENYID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_DATUM_TANARID_OSZTALYCSOPORTID_INTEZMENYID_TANEVID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_DATUM_HELYETTESITOTANARID_OSZTALYCSOPORTID_INTEZMENYID_TANEVID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_DATUM_CSENGETESIRENDID_INTEZMENYID_TANEVID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_TEREMID_DATUM_INTEZMENYID_TANEVID_CSENGETESIRENDID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_TANEVID_ORAKEZDETE_ORAVEGE ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_TEREMID_DATUM_INTEZMENYID_TANEVID_INC_CSENGETESIRENDID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_TANTARGYID_OSZTALYCSOPORTID_TANARID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_TANTARGYID_DATUM_INTEZMENYID_TANEVID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IX_TANITASIORA_TANTARGYID_DATUM_INTEZMENYID_TANEVID_INC_CSENGETESIRENDID ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IDX_TANITASIORA_NAPTARINAPID_ORASZAM ON T_TANITASIORA
GO

DROP INDEX IF EXISTS IDX_TANITASIORA_NAPTARINAPID_TANTARGYID_OSZTALYCSOPORTID ON T_TANITASIORA
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'NCI_TanitasiOra_TantargyId_Datum_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanitasiOra_NaptariNapId_TantargyId_OsztalyCsoportId
    ON T_TANITASIORA (C_NAPTARINAPID, C_TANTARGYID, C_OSZTALYCSOPORTID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'NCI_TanitasiOra_TantargyId_Datum_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanitasiOra_TantargyId_Datum_IntezmenyId_TanevId
    ON T_TANITASIORA (
      C_TANTARGYID
     ,C_DATUM
     ,C_INTEZMENYID
     ,C_TANEVID
  )
  INCLUDE (C_CSENGETESIRENDID)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'NCI_TanitasiOra_OsztalyCsoportId_IntezmenyId_TanevId_TantargyId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanitasiOra_OsztalyCsoportId_IntezmenyId_TanevId_TantargyId
    ON T_TANITASIORA (
       C_OSZTALYCSOPORTID
      ,C_INTEZMENYID
      ,C_TANEVID
      ,C_TANTARGYID) 
  INCLUDE (C_DATUM)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)  
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'NCI_TanitasiOra_Datum_OsztalyCsoportId_TanevId_IntezmenyId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanitasiOra_Datum_OsztalyCsoportId_TanevId_IntezmenyId
    ON dbo.T_TANITASIORA (
       C_DATUM
      ,C_OSZTALYCSOPORTID
      ,C_TANEVID
      ,C_INTEZMENYID
    )
  INCLUDE (C_CSENGETESIRENDID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOra_TantargyId_OsztalyCsoportId_TanarId' ) BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanitasiOra_TantargyId_OsztalyCsoportId_TanarId 
    ON T_TANITASIORA (
       C_TANTARGYID
      ,C_OSZTALYCSOPORTID
      ,C_TANARID
    )
  INCLUDE (
     C_MEGTARTOTT
    ,C_SORSZAMOZANDO
    ,C_ORAKEZDETE
    ,C_INTEZMENYID
    ,C_TANEVID
  ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOra_Datum_TanarId_OsztalyCsoportId_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanitasiOra_Datum_TanarId_OsztalyCsoportId_IntezmenyId_TanevId 
    ON T_TANITASIORA (
       C_DATUM
      ,C_TANARID
      ,C_OSZTALYCSOPORTID
      ,C_INTEZMENYID
      ,C_TANEVID
    ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOra_Datum_HelyettesitoTanarId_OsztalyCsoportId_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanitasiOra_Datum_HelyettesitoTanarId_OsztalyCsoportId_IntezmenyId_TanevId 
    ON T_TANITASIORA (
       C_DATUM
      ,C_HELYETTESITOTANARID
      ,C_OSZTALYCSOPORTID
      ,C_TANEVID
      ,C_INTEZMENYID
    ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOra_IntezmenyId_TanevId_Datum_TanarId_HelyettesitoTanarId') BEGIN
  CREATE INDEX NCI_TanitasiOra_IntezmenyId_TanevId_Datum_TanarId_HelyettesitoTanarId
    ON T_TANITASIORA (
       C_INTEZMENYID
      ,C_TANEVID
      ,C_DATUM
      ,C_TANARID
      ,C_HELYETTESITOTANARID
    ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOra_TeremId_Datum_IntezmenyId_TanevId_CsengetesiRendId') BEGIN
  CREATE INDEX NCI_TanitasiOra_TeremId_Datum_IntezmenyId_TanevId_CsengetesiRendId
    ON T_TANITASIORA (
       C_TEREMID
      ,C_DATUM
      ,C_INTEZMENYID
      ,C_TANEVID
    ) 
  INCLUDE (C_CSENGETESIRENDID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80) 
END

-- ==================================================================================================================================
-- T_ORARENDIORA
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_ORARENDIORA_INTEZMENYID_TANEVID_OSZTALYCSOPORTID ON T_ORARENDIORA
GO
DROP INDEX IF EXISTS IX_ORARENDIORA_INTEZMENYID_TANEVID_CSENGETESIRENDID_ORAERVENYESSEGVEGE ON T_ORARENDIORA
GO
DROP INDEX IF EXISTS IX_ORARENDIORA_TANARID_ORAERVENYESSEGKEZDETE_ORAERVENYESSEGVEGE_INTEZMENYID_TANEVID ON T_ORARENDIORA
GO
DROP INDEX IF EXISTS IX_ORARENDIORA_TEREMID_ORAERVENYESSEGKEZDETE_ORAERVENYESSEGVEGE_INTEZMENYID_TANEVID ON T_ORARENDIORA
GO
DROP INDEX IF EXISTS IX_ORARENDIORA_TANTARGYID_ORAERVENYESSEGKEZDETE_ORAERVENYESSEGVEGE_INTEZMENYID_TANEVID ON T_ORARENDIORA
GO
DROP INDEX IF EXISTS IX_TANITASIORA_TANTARGYID_DATUM_INTEZMENYID_TANEVID_CSENGETESIRENDID ON T_ORARENDIORA
GO
DROP INDEX IF EXISTS IX_ORARENDIORA_ORARENDIORAGROUPID_ORAERVENYESSEGKEZDETE_TANEVID_INTEZMENYID ON T_ORARENDIORA
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_OrarendiOra_OrarendiOraGroupId_OraErvenyessegKezdete_TanevId_IntezmenyId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_OrarendiOra_OrarendiOraGroupId_OraErvenyessegKezdete_TanevId_IntezmenyId
    ON T_ORARENDIORA (
      C_ORARENDIORAGROUPID, 
      C_ORAERVENYESSEGKEZDETE, 
      C_TANEVID, 
      C_INTEZMENYID
    ) 
  INCLUDE(C_ORAERVENYESSEGVEGE) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'NCI_OrarendiOra_OsztalyCsoportId_IntezmenyId_TanevId_HETNAPJA_OraErvenyessegKezdete_OraErvenyessegVege_HETIREND' AND OBJECT_NAME(object_id) = N'T_ORARENDIORA') BEGIN
  CREATE NONCLUSTERED INDEX NCI_OrarendiOra_OsztalyCsoportId_IntezmenyId_TanevId_HETNAPJA_OraErvenyessegKezdete_OraErvenyessegVege_HETIREND
    ON dbo.T_ORARENDIORA (
       C_OSZTALYCSOPORTID
      ,C_INTEZMENYID
      ,C_TANEVID
      ,C_HETNAPJA
      ,C_ORAERVENYESSEGKEZDETE
      ,C_ORAERVENYESSEGVEGE
      ,C_HETIREND
    )
  INCLUDE (C_CSENGETESIRENDID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

--- kell???
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_OrarendiOra_IntezmenyId_TanevId_CsengetesiRendId_OraErvenyessegVege') BEGIN
  CREATE INDEX NCI_OrarendiOra_IntezmenyId_TanevId_CsengetesiRendId_OraErvenyessegVege 
  ON T_ORARENDIORA (C_INTEZMENYID, C_TANEVID, C_CSENGETESIRENDID, C_ORAERVENYESSEGVEGE)
  INCLUDE (TOROLT, C_OSZTALYCSOPORTID)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_OrarendiOra_TanarId_OraErvenyessegKezdete_OraErvenyessegVege_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_OrarendiOra_TanarId_OraErvenyessegKezdete_OraErvenyessegVege_IntezmenyId_TanevId
    ON T_ORARENDIORA (
       C_TANARID 
      ,C_ORAERVENYESSEGKEZDETE
      ,C_ORAERVENYESSEGVEGE
      ,C_INTEZMENYID
      ,C_TANEVID
    ) 
  INCLUDE (C_OSZTALYCSOPORTID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO


IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_OrarendiOra_TeremId_IntezmenyId_OraErvenyessegKezdete_OraErvenyessegVege_TanevId') BEGIN
  CREATE INDEX NCI_OrarendiOra_TeremId_IntezmenyId_OraErvenyessegKezdete_OraErvenyessegVege_TanevId 
    ON T_ORARENDIORA (
       C_TEREMID
      ,C_INTEZMENYID
      ,C_ORAERVENYESSEGKEZDETE
      ,C_ORAERVENYESSEGVEGE
      ,C_TANEVID
    ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_OrarendiOra_TantargyId_IntezmenyId_OraErvenyessegKezdete_OraErvenyessegVege_TanevId') BEGIN
  CREATE INDEX NCI_OrarendiOra_TantargyId_IntezmenyId_OraErvenyessegKezdete_OraErvenyessegVege_TanevId 
    ON T_ORARENDIORA (
       C_TANTARGYID
      ,C_INTEZMENYID
      ,C_ORAERVENYESSEGKEZDETE
      ,C_ORAERVENYESSEGVEGE
      ,C_TANEVID
    ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOra_TantargyId_Datum_IntezmenyId_TanevId') BEGIN
  CREATE INDEX NCI_TanitasiOra_TantargyId_Datum_IntezmenyId_TanevId
    ON T_TANITASIORA (
       C_TANTARGYID
      ,C_DATUM
      ,C_INTEZMENYID
      ,C_TANEVID
    ) 
  INCLUDE (C_CSENGETESIRENDID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80) 
END

-- ==================================================================================================================================
-- T_OSZTALYCSOPORT
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_OSZTALYCSOPORT_TANEVID_INTEZMENYID ON DBO.T_OSZTALYCSOPORT
GO

DROP INDEX IF EXISTS IX_OSZTALYCSOPORT_INTEZMENYID_TANEVID ON DBO.T_OSZTALYCSOPORT
GO

DROP INDEX IF EXISTS IX_OSZTALYCSOPORT_TANEVID_INTEZMENYID_INC_NEV_VEGZOSEVFOLYAM ON DBO.T_OSZTALYCSOPORT
GO

DROP INDEX IF EXISTS UK_TANEV_OSZTALYNEV ON DBO.T_OSZTALYCSOPORT
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_OsztalyCsoport_Nev_IntezmenyId_TanevId') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_OsztalyCsoport_Nev_IntezmenyId_TanevId
    ON T_OSZTALYCSOPORT (C_NEV, C_INTEZMENYID, C_TANEVID)
  WHERE TOROLT = 'F' 
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_OsztalyCsoport_TanevId_IntezmenyId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_OsztalyCsoport_TanevId_IntezmenyId
    ON dbo.T_OSZTALYCSOPORT (C_TANEVID , C_INTEZMENYID)
  INCLUDE (C_NEV, C_VEGZOSEVFOLYAM)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_TANULOMULASZTAS
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TANULOMULASZTAS_ORATANULOIID_C_TANITASIORAKID_TIPUS ON T_TANULOMULASZTAS
GO

DROP INDEX IF EXISTS IX_TANULOMULASZTAS_ORATANULOIID_TANITASIORAKID_TIPUS_INTEZMENYID_TANEVID ON T_TANULOMULASZTAS
GO

DROP INDEX IF EXISTS IDX_TANULOMULASZTAS_ORATANULOIID_C_TANITASIORAKID ON T_TANULOMULASZTAS
GO

DROP INDEX IF EXISTS IX_TANULOMULASZTAS_TIPUS_ORATANULOIID_TANITASIORAKID ON T_TANULOMULASZTAS
GO

DROP INDEX IF EXISTS IX_TANULOMULASZTAS_ORATANULOIID_TIPUS_TANITASIORAKID_INTEZMENYID_TANEVID ON T_TANULOMULASZTAS
GO

DROP INDEX IF EXISTS IX_TANULOMULASZTAS_ORATANULOIID_TANITASIORAKID_TIPUS_INTEZMENYID_TANEVID_KESESPERCBEN ON T_TANULOMULASZTAS
GO

DROP INDEX IF EXISTS IX_TANULOMULASZTAS_INTEZMENYID_TANEVID_ORATANULOIID_TANITASIORAKID_TIPUS ON T_TANULOMULASZTAS
GO

DROP INDEX IF EXISTS IX_TANULOMULASZTAS_ORATANULOIID_TANITASIORAKID_TIPUS_INTEZMENYID_TANEVID_INC_KESESPERCBEN ON T_TANULOMULASZTAS
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloMulasztas_OraTanuloiId_TanitasiOrakId_Tipus_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanuloMulasztas_OraTanuloiId_TanitasiOrakId_Tipus_IntezmenyId_TanevId
    ON T_TANULOMULASZTAS (
       C_ORATANULOIID
      ,C_TANITASIORAKID
      ,C_TIPUS
      ,C_INTEZMENYID
      ,C_TANEVID
    ) 
  INCLUDE(
     C_KESESPERCBEN
    ,C_IGAZOLASTIPUSA
  )
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloMulasztas_TanitasiOrakId_IntezmenyId_TanevId_OraTanuloiId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanuloMulasztas_TanitasiOrakId_IntezmenyId_TanevId_OraTanuloiId
    ON T_TANULOMULASZTAS (
       C_TANITASIORAKID
      ,C_INTEZMENYID
      ,C_TANEVID
      ,C_ORATANULOIID
    ) 
  INCLUDE(
     C_KESESPERCBEN
    ,C_IGAZOLASTIPUSA
    ,C_TIPUS
  )
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_NAPTARINAP
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_NAPTARINAP_INTEZMENYID_TANEVID_NAPDATUMA_ORARENDINAP ON T_NAPTARINAP
GO

DROP INDEX IF EXISTS IX_NAPTARINAP_INTEZMENYID_TANEVID_NAPDATUMA ON T_NAPTARINAP
GO


IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'CI_NaptariNap_NapDatuma_IntezmenyId_TanevId') BEGIN
  CREATE CLUSTERED INDEX CI_NaptariNap_NapDatuma_IntezmenyId_TanevId
    ON T_NAPTARINAP (C_NAPDATUMA, C_INTEZMENYID, C_TANEVID)
  WITH (FILLFACTOR = 80)  
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_NaptariNap_IntezmenyId_TanevId_NapDatuma_OrarendiNap') BEGIN
  CREATE INDEX NCI_NaptariNap_IntezmenyId_TanevId_NapDatuma_OrarendiNap 
    ON T_NAPTARINAP (
       C_INTEZMENYID
      ,C_TANEVID
      ,C_NAPDATUMA
      ,C_ORARENDINAP
    ) 
  INCLUDE (C_HETNAPJA, C_HETIREND)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO  


-- ==================================================================================================================================
-- T_HAZIFELADATOK
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_HAZIFELADATOK_FELADASDATUMA_OSZTALYCSOPORTID_TANTARGYID ON T_HAZIFELADATOK
GO
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_HaziFeladatok_FeladasDatuma_OsztalyCsoportId_TantargyId' ) BEGIN
  CREATE NONCLUSTERED INDEX NCI_HaziFeladatok_FeladasDatuma_OsztalyCsoportId_TantargyId 
    ON T_HAZIFELADATOK (
       C_FELADASDATUMA
      ,C_OSZTALYCSOPORTID
      ,C_TANTARGYID
    ) 
  INCLUDE (
     C_ROGZITOID
    ,C_ORASZAM
  )
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO


-- ==================================================================================================================================
-- T_DICTIONARYITEMBASE
-- ==================================================================================================================================
DROP INDEX IF EXISTS UK_DICTIONARYITEMBASE ON T_DICTIONARYITEMBASE
GO

DROP INDEX IF EXISTS UK_DICTIONARYITEMBASE_INTEZMENYID_TANEVID_TYPE_NAME ON T_DICTIONARYITEMBASE
GO

DROP INDEX IF EXISTS IDXMIG_DICTIONARYITEMBASE_TANEVID_TYPE_NAME ON T_DICTIONARYITEMBASE
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name='NCU_DictionaryItemBase_IntezmenyId_TanevId_Type_Name') BEGIN
  CREATE UNIQUE INDEX NCU_DictionaryItemBase_IntezmenyId_TanevId_Type_Name 
    ON T_DICTIONARYITEMBASE (
    	 C_INTEZMENYID
    	,C_TANEVID
    	,C_TYPE
    	,C_NAME
    ) 
  INCLUDE (C_VALUE, C_ORDER) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO


-- ==================================================================================================================================
-- T_CSENGETESIRENDORA
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_CSENGETESIRENDORA_INTEZMENYID_CSENGETESIRENDID_ORASZAM ON T_CSENGETESIRENDORA
GO

DROP INDEX IF EXISTS UK_CSENGETESIRENDORA_CSENGETESIRENDID_ORASZAM ON T_CSENGETESIRENDORA
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_CsengetesiRendOra_IntezmenyId_CsengetesiRendId_OraSzam') BEGIN
  CREATE NONCLUSTERED INDEX NCI_CsengetesiRendOra_IntezmenyId_CsengetesiRendId_OraSzam 
    ON T_CSENGETESIRENDORA (
       C_INTEZMENYID
      ,C_TANEVID
      ,C_CSENGETESIRENDID
      ,C_ORASZAM
    )
  INCLUDE (C_KEZDETE, C_VEGE)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO


IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_CsengetesiRendOra_CsengetesiRendId_OraSzam') BEGIN
  CREATE UNIQUE INDEX NCU_CsengetesiRendOra_CsengetesiRendId_OraSzam
    ON T_CSENGETESIRENDORA (C_CSENGETESIRENDID, C_ORASZAM)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO


-- ==================================================================================================================================
-- T_HELYETTESITESIIDOSZAK
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_HELYETTESITESIIDOSZAK_INTEZMENYID_HELYETTESITETTORARENDID ON T_HELYETTESITESIIDOSZAK
GO

DROP INDEX IF EXISTS IX_HELYETTESITESIIDOSZAK_HELYETTESITETTORARENDID_HELYETTESITESNAPJA_HELYETTESTANAROKID_INTEZMENYID ON T_HELYETTESITESIIDOSZAK
GO

DROP INDEX IF EXISTS IX_HELYETTESITESIIDOSZAK_HELYETTESITESNAPJA_HELYETTESTANAROKID_INTEZMENYID ON T_HELYETTESITESIIDOSZAK
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_HelyettesitesiIdoszak_IntezmenyId_HelyettesitettOrarendId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_HelyettesitesiIdoszak_IntezmenyId_HelyettesitettOrarendId
    ON T_HELYETTESITESIIDOSZAK (C_INTEZMENYID ,C_HELYETTESITETTORARENDID)
  INCLUDE (C_HELYETTESITESNAPJA, C_HELYETTESTANAROKID, C_TANEVID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_HelyettesitesiIdoszak_HelyettesitesNapja_HelyettesTanarokId_IntezmenyId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_HelyettesitesiIdoszak_HelyettesitesNapja_HelyettesTanarokId_IntezmenyId 
    ON dbo.T_HELYETTESITESIIDOSZAK (
    	 C_HELYETTESITESNAPJA
    	,C_HELYETTESTANAROKID
    	,C_INTEZMENYID
    ) 
  INCLUDE (C_TANEVID, C_HELYETTESITETTORARENDID)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_FELHASZNALO
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_FELHASZNALO_INTEZMENYID_ID ON T_FELHASZNALO
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Felhasznalo_IntezmenyId_Id') BEGIN
  CREATE INDEX NCI_Felhasznalo_IntezmenyId_Id 
    ON T_FELHASZNALO (C_INTEZMENYID, ID) 
  INCLUDE (C_NYOMTATASINEV, C_TANEVID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO


-- ==================================================================================================================================
-- T_TEREM
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TEREM_INTEZMENYID_ID ON T_TEREM
GO

DROP INDEX IF EXISTS UK_TEREMNEV ON T_TEREM
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Terem_IntezmenyId_TanevId_Nev_MukodesiHelyId') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_Terem_IntezmenyId_TanevId_Nev_MukodesiHelyId
    ON dbo.T_TEREM (C_INTEZMENYID , C_TANEVID , C_NEV , C_MUKODESIHELYID)
  WHERE TOROLT='F'
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Terem_IntezmenyId_Id') BEGIN
  CREATE INDEX NCI_Terem_IntezmenyId_Id 
    ON T_TEREM (C_INTEZMENYID, ID) 
  INCLUDE (C_NEV, C_TANEVID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_TANTARGY
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TANTARGY_INTEZMENYID_ID ON T_TANTARGY
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Tantargy_IntezmenyId_Id') BEGIN
  CREATE INDEX NCI_Tantargy_IntezmenyId_Id 
    ON T_TANTARGY (C_INTEZMENYID, ID) 
  INCLUDE (C_NEV, C_ROVIDNEV, C_TARGYKATEGORIA, C_TANEVID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_TANEVRENDJE
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TANEVRENDJE_TANEVID_INTEZMENYID_NAPTIPUSA ON T_TANEVRENDJE
GO

DROP INDEX IF EXISTS IX_TANEVRENDJE_DATUM_INTEZMENYID_TANEVID ON T_TANEVRENDJE
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanevRendje_IntezmenyId_NapTipusa_TanevId_Datum') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanevRendje_IntezmenyId_NapTipusa_TanevId_Datum
    ON T_TANEVRENDJE (
       C_INTEZMENYID
      ,C_NAPTIPUSA
      ,C_TANEVID
      ,C_DATUM
    ) 
  INCLUDE (C_ORARENDINAP, C_OSSZESCSOPORTRAVONATKOZIK, C_CSENGETESIRENDID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanevRendje_Datum_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanevRendje_Datum_IntezmenyId_TanevId
    ON T_TANEVRENDJE (
       C_DATUM
      , C_TANEVID
      , C_INTEZMENYID
    )
  INCLUDE (C_OSSZESCSOPORTRAVONATKOZIK, C_CSENGETESIRENDID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_IGAZOLAS
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_IGAZOLAS_TANULOID_KEZDETE_VEGE_INTEZMENYID_TANEVID ON T_IGAZOLAS
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Igazolas_TanuloId_Kezdete_Vege_IntezmenyId_TanevId') BEGIN
  CREATE INDEX NCI_Igazolas_TanuloId_Kezdete_Vege_IntezmenyId_TanevId 
    ON T_IGAZOLAS (C_TANULOID, C_KEZDETE, C_VEGE, C_INTEZMENYID, C_TANEVID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END


-- ==================================================================================================================================
-- T_TANULOMENTESSEG
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TANULOMENTESSEG_TANULOID_TANTARGYID_KEZDETE_VEGE_INTEZMENYID_TANEVID ON T_TANULOMENTESSEG
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloMentesseg_TanuloId_TantargyId_Kezdete_Vege_IntezmenyId_TanevId') BEGIN
  CREATE INDEX NCI_TanuloMentesseg_TanuloId_TantargyId_Kezdete_Vege_IntezmenyId_TanevId 
    ON T_TANULOMENTESSEG (C_TANULOID, C_TANTARGYID, C_KEZDETE, C_VEGE, C_INTEZMENYID, C_TANEVID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END

-- ==================================================================================================================================
-- T_GONDVISELO
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_GONDVISELO_TANULOID_INTEZMENYID_TANEVID ON T_GONDVISELO
GO
DROP INDEX IF EXISTS IX_GONDVISELO_TANULOID_INTEZMENYID_TANEVID_INC_NEV ON T_GONDVISELO
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Gondviselo_TanuloId_IntezmenyId_TanevId') BEGIN
  CREATE INDEX NCI_Gondviselo_TanuloId_IntezmenyId_TanevId 
    ON T_GONDVISELO (C_TANULOID, C_INTEZMENYID, C_TANEVID) 
  INCLUDE (C_NEV) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END

-- ==================================================================================================================================
-- T_TELEFON
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TELEFON_GONDVISELOID_ALAPERTELMEZETT_INTEZMENYID_TANEVID_TELEFONSZAM ON T_TELEFON
GO

DROP INDEX IF EXISTS IX_TELEFON_GONDVISELOID_ALAPERTELMEZETT_INTEZMENYID_TANEVID_INC_TELEFONSZAM ON T_TELEFON
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Telefon_GondviseloId_Alapertelmezett_IntezmenyId_TanevId') BEGIN
  CREATE INDEX NCI_Telefon_GondviseloId_Alapertelmezett_IntezmenyId_TanevId 
    ON T_TELEFON (C_GONDVISELOID, C_ALAPERTELMEZETT, C_INTEZMENYID, C_TANEVID) 
  INCLUDE (C_TELEFONSZAM) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_TANMENET
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TANTARGYID_OSZTALYCSOPORTID_INTEZMENYID_TANEVID_ORASZAM ON T_TANMENET
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TantargyId_OsztalyCsoportId_IntezmenyId_TanevId_OraSzam') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TantargyId_OsztalyCsoportId_IntezmenyId_TanevId_OraSzam 
    ON T_TANMENET (
       C_TANTARGYID 
      ,C_OSZTALYCSOPORTID 
      ,C_INTEZMENYID 
      ,C_TANEVID 
      ,C_ORASZAM
    ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)	
END
GO


-- ==================================================================================================================================
-- T_TANULOERTEKELES
-- ==================================================================================================================================
DROP INDEX IF EXISTS IX_TANULOERTEKELES_TANULOID_TIPUSID_INTEZMENYID_TANEVID_ERTEKELESOSZTALYZATID ON T_TANULOERTEKELES
GO
DROP INDEX IF EXISTS IDX_TANULOERTEKELES_TANULOID_TANTARGYID_ERTEKELESTIPUSA ON T_TANULOERTEKELES
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloErtekeles_TanuloId_TantargyId_IntezmenyId_TanevId_TipusaId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanuloErtekeles_TanuloId_TantargyId_IntezmenyId_TanevId_TipusaId
    ON T_TANULOERTEKELES (
      C_TANULOID, C_TANTARGYID, C_INTEZMENYID, C_TANEVID, C_TIPUSID 
    )
    INCLUDE (C_ERTEKELESOSZTALYZATID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)  
END
GO


IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloErtekeles_TanuloId_TipusId_IntezmenyId_TanevId_ErtekelesOsztalyzatId') BEGIN
  CREATE INDEX NCI_TanuloErtekeles_TanuloId_TipusId_IntezmenyId_TanevId_ErtekelesOsztalyzatId
    ON T_TANULOERTEKELES (C_TANULOID, C_TIPUSID, C_INTEZMENYID, C_TANEVID, C_ERTEKELESOSZTALYZATID) 
  INCLUDE (C_ERTEKELESMODID, C_ROGZITESKORITANULOOSZTALYID, C_TANTARGYID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_DICTIONARYTYPE
-- ==================================================================================================================================
DROP INDEX IF EXISTS UK_DICTIONARYTYPE_INTEZMENYID_TANEVID_CODENAME ON dbo.T_DICTIONARYTYPE
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_DictionaryType_IntezmenyId_TanevId_CodeName') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_DictionaryType_IntezmenyId_TanevId_CodeName
    ON dbo.T_DICTIONARYTYPE(C_INTEZMENYID, C_TANEVID, C_CODENAME)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================================================================================================================
-- T_MOBILDBINFO
-- ==================================================================================================================================
ALTER TABLE T_MOBILDBINFO DROP CONSTRAINT IF EXISTS UK_MOBILDBINFO_INTEZMENYID 
GO

DROP INDEX IF EXISTS UK_MOBILDBINFO_INTEZMENYID ON dbo.T_MOBILDBINFO
GO


IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_MobilDbInfo_IntezmenyId') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_MobilDbInfo_IntezmenyId
    ON dbo.T_MOBILDBINFO (C_INTEZMENYID)
  WITH (FILLFACTOR = 80) 
END
GO

-- ==================================================================================================================================
-- T_DICTIONARYITEMBASE & T_DICTIONARYTYPE CONSTRAINTS
-- ================================================================================================================================== 
ALTER TABLE T_DICTIONARYITEMBASE
DROP CONSTRAINT IF EXISTS FK_4028090_4028089
GO

ALTER TABLE T_DICTIONARYTYPE
DROP CONSTRAINT IF EXISTS PK_T_4028083
GO

ALTER TABLE T_DICTIONARYTYPE
ADD CONSTRAINT PK_T_4028083 PRIMARY KEY CLUSTERED (ID, C_INTEZMENYID, C_TANEVID)
GO

ALTER TABLE [dbo].[T_DICTIONARYITEMBASE] WITH NOCHECK
ADD CONSTRAINT [FK_4028090_4028089] FOREIGN KEY ([C_DICTIONARYTYPEID], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_DICTIONARYTYPE] (ID, C_INTEZMENYID, C_TANEVID);
GO

