﻿-- ==================================
-- T_CIM
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Cim_ElozotanevirekordId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_Cim_ElozotanevirekordId
    ON T_CIM (ELOZOTANEVIREKORDID)
  INCLUDE (C_INTEZMENYID)
  WITH (FILLFACTOR = 80)  
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Cim_FelhasznaloId_Gondviseloid_CimTipusa_IntezmenyId') BEGIN
  CREATE INDEX NCI_Cim_FelhasznaloId_Gondviseloid_CimTipusa_IntezmenyId
  ON T_CIM(
     C_FELHASZNALOID
    ,C_GONDVISELOID
    ,C_CIMTIPUSA
    ,C_INTEZMENYID
  )
  INCLUDE(C_AJTO,C_EMELET,C_HAZSZAM,C_IRANYITOSZAM,C_KOZTERULET,C_VAROS,C_ALAPERTELMEZETT,C_TANEVID,C_KOZTERULETJELLEGENEV)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Cim_FelhasznaloId_GondviseloId_TanevId') BEGIN
  CREATE UNIQUE INDEX NCU_Cim_FelhasznaloId_GondviseloId_TanevId
     ON T_CIM (
        C_FELHASZNALOID
       ,C_GONDVISELOID
       ,C_TANEVID)
     WHERE TOROLT = 'F' AND C_ALAPERTELMEZETT = 'T'
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Cim_IntezmenyId_TanevId_KozteruletJellege') BEGIN
  CREATE NONCLUSTERED INDEX [NCI_Cim_IntezmenyId_TanevId_KozteruletJellege] 
  ON [dbo].[T_CIM]
  (
    [C_INTEZMENYID] ASC,
    [C_TANEVID] ASC,
    [C_KOZTERULETJELLEGENEV] ASC
  )
END
GO

-- ==================================
-- T_CSENGETESIREND
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Csengetesirend_TanevId_IntezmenyId_Nev') BEGIN
CREATE UNIQUE INDEX NCU_Csengetesirend_TanevId_IntezmenyId_Nev
  ON T_CSENGETESIREND (
     C_TANEVID
    ,C_INTEZMENYID
    ,C_NEV
   )
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_CSENGETESIRENDORA
-- ==================================
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
    )
    INCLUDE (C_TANEVID, C_INTEZMENYID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Csoport_AlintezmenyId_AltanevId') BEGIN
  CREATE INDEX NCI_Csoport_AlintezmenyId_AltanevId 
    ON T_CSOPORT (C_ALINTEZMENYID, C_ALTANEVID) 
    INCLUDE(C_OSZTALYBONTASID, C_TIPUSA) 
    WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ===============================
-- T_CSOPORT
-- ===============================
IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCI_Csoport_Intezmeny_Tanev') BEGIN
  CREATE NONCLUSTERED INDEX [NCI_Csoport_Intezmeny_Tanev]
    ON T_CSOPORT (
       C_ALINTEZMENYID
      ,C_ALTANEVID
    )
  INCLUDE (C_OSZTALYBONTASID) 
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCI_Csoport_Tipusa_AlintezmenyId_AltanevId') BEGIN
  CREATE INDEX NCI_Csoport_Tipusa_AlintezmenyId_AltanevId 
    ON T_CSOPORT (C_TIPUSA, C_ALINTEZMENYID, C_ALTANEVID)
  WITH (FILLFACTOR = 80)
END
GO
-- ===============================
-- T_CSOPORTTIPUS
-- ===============================
IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCI_CsoportTipus_AlTanevId_AlIntezmenyId') BEGIN
  CREATE INDEX NCI_CsoportTipus_AlTanevId_AlIntezmenyId  
  ON T_CSOPORTTIPUS (
     C_ALTANEVID
    ,C_ALINTEZMENYID
  )
  WHERE (C_ISTANORAICELU = 'T' AND TOROLT = 'F')
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_DICTIONARYITEMBASE
-- ==================================
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

IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name='NCI_DictionaryItembase_DictionaryTpyeId_IntezmenyId_TanevId') BEGIN
CREATE NONCLUSTERED INDEX NCI_DictionaryItembase_DictionaryTpyeId_IntezmenyId_TanevId
  ON T_DICTIONARYITEMBASE (
     C_DICTIONARYTYPEID
    ,C_INTEZMENYID
    ,C_TANEVID
  )
  INCLUDE (C_VISIBLE,C_NAME,C_NAME_1,C_NAME_2,C_NAME_3,C_NAME_4,C_TYPE,C_PROTECTED,C_COLOR,C_ORDER)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

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

-- ==================================
-- T_DICTIONARYTYPE
-- ==================================
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_TANITASIORADIGTAMESZKOZ
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_TanitasiOraDigTamEszkoz_TanitasioraId_DigTamEszkozTipusId') BEGIN -- Torolt szűrés nem kell
  CREATE UNIQUE INDEX NCU_TanitasiOraDigTamEszkoz_TanitasioraId_DigTamEszkozTipusId ON T_TANITASIORADIGTAMESZKOZ (C_TANITASIORAID, C_DIGTAMESZKOZTIPUSID)
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_EMAIL
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Email_ElozotanevirekordId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_Email_ElozotanevirekordId
    ON T_EMAIL (ELOZOTANEVIREKORDID)
  INCLUDE (C_INTEZMENYID)
  WITH (FILLFACTOR = 80)  
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Email_FelhasznaloId_GondviseloId_IntezmenyId') BEGIN
  CREATE INDEX NCI_Email_FelhasznaloId_GondviseloId_IntezmenyId 
  ON T_EMAIL(
     C_FELHASZNALOID
    ,C_GONDVISELOID
    ,C_INTEZMENYID
  )
  INCLUDE(C_EMAILCIM,C_TANEVID)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Email_FelhasznaloId_GondviseloId_TanevId') BEGIN
  CREATE UNIQUE INDEX NCU_Email_FelhasznaloId_GondviseloId_TanevId
    ON T_EMAIL (
      C_FELHASZNALOID
      ,C_GONDVISELOID
      ,C_TANEVID)
    WHERE TOROLT = 'F' AND C_ALAPERTELMEZETT = 'T'
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Email_FelhasznaloId_GondviseloId_TanevId_Telefonszam') BEGIN
  CREATE UNIQUE INDEX NCU_Email_FelhasznaloId_GondviseloId_TanevId_Telefonszam
     ON T_EMAIL (
        C_FELHASZNALOID
       ,C_GONDVISELOID
       ,C_TANEVID
       ,C_EMAILCIM
	     ,C_ISPUBLIC)
     WHERE TOROLT = 'F' 
END
GO
​
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Email_FelhasznaloId_TanevId') BEGIN
  CREATE UNIQUE INDEX NCU_Email_FelhasznaloId_TanevId
     ON T_EMAIL (
        C_FELHASZNALOID
       ,C_TANEVID)
     WHERE 
       TOROLT = 'F' 
       AND C_ISPUBLIC = 'T' 
       AND C_GONDVISELOID IS NULL
END
GO

-- ==================================
-- T_FELHASZNALO
-- ==================================
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_SZULETESIDATUM, C_UTONEV, C_VEZETEKNEV, C_NEVSORREND, C_ANYJANEVE, C_SZULETESIHELY, C_OKTATASIAZONOSITO)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

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

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Felhasznalo_EgyediAzonosito_TanevId_IntezmenyId') BEGIN
  CREATE INDEX NCI_Felhasznalo_EgyediAzonosito_TanevId_IntezmenyId
  ON T_FELHASZNALO(
     C_EGYEDIAZONOSITO
    ,C_TANEVID
    ,C_INTEZMENYID
  )
  INCLUDE (C_ANYJANEVE,C_SZULETESIDATUM,C_SZULETESINEV,C_SZULETESIHELY)
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Felhasznalo_AnyjaNeve_SzuletesiDatum_SzuletesiNev_SzuletesiHely_TanevId_IntezmenyId') BEGIN
  CREATE INDEX NCI_Felhasznalo_AnyjaNeve_SzuletesiDatum_SzuletesiNev_SzuletesiHely_TanevId_IntezmenyId
  ON T_FELHASZNALO(
     C_ANYJANEVE
    ,C_SZULETESIDATUM
    ,C_SZULETESINEV
    ,C_SZULETESIHELY
    ,C_TANEVID
    ,C_INTEZMENYID
  )
  INCLUDE (C_EGYEDIAZONOSITO)
  WITH (FILLFACTOR = 80)
END
GO

IF EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Felhasznalo_IntezmenyId_TanevId_Neme') BEGIN
  DROP INDEX NCI_Felhasznalo_IntezmenyId_TanevId_Neme ON T_FELHASZNALO;
  CREATE INDEX NCI_Felhasznalo_IntezmenyId_TanevId_Neme
  ON T_FELHASZNALO(
  	C_INTEZMENYID,
	  C_TANEVID,
	  C_NEME
  )
  INCLUDE (C_NYOMTATASINEV, C_IDPEGYEDIAZONOSITO, C_OKTATASIAZONOSITO, TOROLT)
  WITH (FILLFACTOR = 80);
END
GO

-- ==================================
-- T_FELHASZNALOBELEPES
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_FelhasznaloBelepes_FelhasznaloIdIntezmenyId_TanevId') BEGIN
  CREATE INDEX NCI_FelhasznaloBelepes_FelhasznaloIdIntezmenyId_TanevId 
    ON T_FELHASZNALOBELEPES (C_FELHASZNALOID, C_INTEZMENYID, C_TANEVID) 
    INCLUDE(C_GONDVISELOID) 
    WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_FELHASZNALOBELEPESTORTENET
-- ==================================
IF INDEXPROPERTY(OBJECT_ID('dbo.T_FELHASZNALOBELEPESTORTENET'), 'PK_FelhasznaloBelepesTortenet ', 'IsClustered') = 1
    BEGIN

    ALTER TABLE dbo.T_FELHASZNALOBELEPESTORTENET
        DROP CONSTRAINT PK_FelhasznaloBelepesTortenet;

    ALTER TABLE dbo.T_FELHASZNALOBELEPESTORTENET
        ADD CONSTRAINT PK_FelhasznaloBelepesTortenet PRIMARY KEY NONCLUSTERED (ID) WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

    END

IF INDEXPROPERTY(OBJECT_ID('dbo.T_FELHASZNALOBELEPESTORTENET'), 'CCI_FelhasznaloBelepesTortenet', 'IndexID') IS NULL
    CREATE CLUSTERED COLUMNSTORE INDEX CCI_FelhasznaloBelepesTortenet ON dbo.T_FELHASZNALOBELEPESTORTENET
    WITH (DATA_COMPRESSION = COLUMNSTORE_ARCHIVE);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_FELHASZNALOBELEPESTORTENET'), 'NCI_FelhasznaloBelepesTortenet_FelhasznaloId', 'IndexID') IS NOT NULL
    ALTER INDEX [NCI_FelhasznaloBelepesTortenet_FelhasznaloId] ON dbo.T_FELHASZNALOBELEPESTORTENET
    REBUILD
    WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_FELHASZNALOBELEPESTORTENET'), 'NCI_FelhasznaloBelepesTortenet_GondviseloId', 'IndexID') IS NOT NULL
    ALTER INDEX [NCI_FelhasznaloBelepesTortenet_GondviseloId] ON dbo.T_FELHASZNALOBELEPESTORTENET
    REBUILD
    WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_FELHASZNALOBELEPESTORTENET'), 'NCI_FelhasznaloBelepesTortenet_IntezmenyId', 'IndexID') IS NOT NULL
    ALTER INDEX [NCI_FelhasznaloBelepesTortenet_IntezmenyId] ON dbo.T_FELHASZNALOBELEPESTORTENET
    REBUILD
    WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_FELHASZNALOBELEPESTORTENET'), 'NCI_FelhasznaloBelepesTortenet_TanevId', 'IndexID') IS NOT NULL
    ALTER INDEX [NCI_FelhasznaloBelepesTortenet_TanevId] ON dbo.T_FELHASZNALOBELEPESTORTENET
    REBUILD
    WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_FELHASZNALOBELEPESTORTENET'), 'NCI_FelhasznaloBelepesTortenet_IntezmenyId_TanevId', 'IndexID') IS NULL
    CREATE INDEX [NCI_FelhasznaloBelepesTortenet_IntezmenyId_TanevId] ON dbo.T_FELHASZNALOBELEPESTORTENET(
        [C_INTEZMENYID], [C_TANEVID], [C_SESSIONID], [C_FELHASZNALOID], [C_GONDVISELOID] 
    )
    WITH (FILLFACTOR = 100, PAD_INDEX = ON)
GO

-- ==================================
-- T_FOGLALKOZAS
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Foglalkozas_IntezmenyId_TanevId_TantargyId_OsztalyCsoportId') BEGIN
  CREATE INDEX NCI_Foglalkozas_IntezmenyId_TanevId_TantargyId_OsztalyCsoportId
  ON T_FOGLALKOZAS (
     C_INTEZMENYID
    ,C_TANEVID
    ,C_TANTARGYID
    ,C_OSZTALYCSOPORTID
  ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO
-- ==================================
-- T_GONDVISELO
-- ==================================
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
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Gondviselo_ElozotanevirekordId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_Gondviselo_ElozotanevirekordId
    ON T_GONDVISELO (ELOZOTANEVIREKORDID)
  INCLUDE (C_INTEZMENYID)
  WITH (FILLFACTOR = 80)  
END
GO

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

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

-- ==================================
-- T_HAZIFELADATOK
-- ==================================
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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_HaziFeladatok_OsztalyCsoportId_Hatarido' ) BEGIN
  CREATE INDEX NCI_HaziFeladatok_OsztalyCsoportId_Hatarido 
    ON T_HAZIFELADATOK (C_OSZTALYCSOPORTID, C_HATARIDO) 
  INCLUDE (C_TANEVID, C_INTEZMENYID) 
  WHERE TOROLT = 'F' 
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Hazifeladatok_IntezmenyId_TanevId_FeladasDatuma' ) BEGIN
  CREATE NONCLUSTERED INDEX NCI_Hazifeladatok_IntezmenyId_TanevId_FeladasDatuma
    ON [dbo].[T_HAZIFELADATOK] ([C_INTEZMENYID],[C_TANEVID],[C_FELADASDATUMA])
  INCLUDE ([C_TANITASIORAID],[C_ORARENDIORAID])
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Hazifeladatok_TanevId_IntezmenyId_TanitasiOraId' ) BEGIN
  CREATE UNIQUE INDEX NCU_Hazifeladatok_TanevId_IntezmenyId_TanitasiOraId
  ON T_HAZIFELADATOK (
     C_TANEVID
    ,C_INTEZMENYID
    ,C_TANITASIORAID
  )
  WHERE TOROLT='F' AND C_TANITASIORAID IS NOT NULL
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Hazifeladatok_TanevId_IntezmenyId_OrarendiOraId_FeladasDatuma' ) BEGIN
  CREATE UNIQUE INDEX NCU_Hazifeladatok_TanevId_IntezmenyId_OrarendiOraId_FeladasDatuma
  ON T_HAZIFELADATOK (
     C_TANEVID
    ,C_INTEZMENYID
    ,C_ORARENDIORAID
    ,C_FELADASDATUMA
  )
  WHERE TOROLT='F' AND C_ORARENDIORAID IS NOT NULL
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_HELYETTESITESIIDOSZAK
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_HelyettesitesiIdoszak_IntezmenyId_HelyettesitettOrarendId') BEGIN
    CREATE UNIQUE NONCLUSTERED INDEX NCI_HelyettesitesiIdoszak_IntezmenyId_HelyettesitettOrarendId ON dbo.T_HELYETTESITESIIDOSZAK
    (
      C_INTEZMENYID ASC,
      C_HELYETTESITETTORARENDID ASC,
      C_HELYETTESITESNAPJA ASC
    )
    INCLUDE(C_TANEVID, C_HELYETTESTANAROKID) 
    WHERE (TOROLT = 'F')
    WITH (FILLFACTOR = 90)
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

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE [name] = 'NCI_HelyettesitesiIdoszak_HelyettesitesNapja_IntezmenyId_TanevId_HelyettesTanarokId') BEGIN
  CREATE INDEX NCI_HelyettesitesiIdoszak_HelyettesitesNapja_IntezmenyId_TanevId_HelyettesTanarokId 
    ON T_HELYETTESITESIIDOSZAK (C_HELYETTESITESNAPJA, C_INTEZMENYID, C_TANEVID, C_HELYETTESTANAROKID) 
  INCLUDE (C_HELYETTESITESTIPUS, C_HELYETTESITESOKA, C_HELYETTESITETTORARENDID)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO
-- ==================================
-- T_IGAZOLAS
-- ==================================
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
GO

-- ==================================
-- T_INTEZMENYCONFIG
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_IntezmenyConfig_IntezmenyId_ConfigId') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_IntezmenyConfig_IntezmenyId_ConfigId 
    ON dbo.T_INTEZMENYCONFIG (C_INTEZMENYID, C_CONFIGTIPUSID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_KKAMIVEGZETTSEG
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKAmiVegzettseg_AlkalmazottId_IntezmenyId') BEGIN
CREATE INDEX NCI_KKAmiVegzettseg_AlkalmazottId_IntezmenyId
  ON T_KKAMIVEGZETTSEG (
      C_ALKALMAZOTTID
     ,C_INTEZMENYID
  )
  INCLUDE (ELOZOTANEVIREKORDID)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
-- ==================================
-- T_KKELEKTROAKUZENE
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKElektroAkuZene_KKAmiVegzettsegId_IntezmenyId') BEGIN
CREATE INDEX NCI_KKElektroAkuZene_KKAmiVegzettsegId_IntezmenyId
  ON T_KKELEKTROAKUZENE (
     C_KKAMIVEGZETTSEGID
    ,C_INTEZMENYID
  )
  INCLUDE (ELOZOTANEVIREKORDID,C_ELEKTRAKUTIPUSID,LASTCHANGED,MODIFIER)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKElektroAkuZene_ElozoTaneviRekordId') BEGIN
CREATE INDEX NCI_KKElektroAkuZene_ElozoTaneviRekordId
  ON T_KKELEKTROAKUZENE (
      ELOZOTANEVIREKORDID
  )
  INCLUDE (C_INTEZMENYID)
  WITH (FILLFACTOR = 80)
END  

-- ==================================
-- T_KKGYOGYPEDVEGZETTSEG
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKGyogypedVegzettseg_IntezmenyId') BEGIN
DROP INDEX IF EXISTS T_KKGYOGYPEDVEGZETTSEG.NCI_KKGyogypedVegzettseg_IntezmenyId
  CREATE INDEX NCI_KKGyogypedVegzettseg_IntezmenyId
    ON T_KKGYOGYPEDVEGZETTSEG (
        C_INTEZMENYID
  )
  INCLUDE (ELOZOTANEVIREKORDID,TOROLT,SERIAL,LASTCHANGED,MODIFIER)
  WITH (FILLFACTOR = 80)
END
-- ==================================
-- T_KKTANARVEGZETTSEG
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKTanarVegzettseg_IntezmenyId_AlkalmazottId') BEGIN
  CREATE INDEX NCI_KKTanarVegzettseg_IntezmenyId_AlkalmazottId 
    ON T_KKTANARVEGZETTSEG (
        C_ALKALMAZOTTID
     ,C_INTEZMENYID
  )
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKTanarVegzettseg_IntezmenyId_ElozoTaneviRekordid') BEGIN
  CREATE INDEX NCI_KKTanarVegzettseg_IntezmenyId_ElozoTaneviRekordid
    ON T_KKTANARVEGZETTSEG (
         ELOZOTANEVIREKORDID
    ,C_INTEZMENYID
  )
  INCLUDE (C_KKTANARVEGZETTSEGID,TOROLT,SERIAL,LASTCHANGED,MODIFIER)
  WITH (FILLFACTOR = 80)
END
GO
-- ==================================
-- T_KKTANITOVEZGETTSEG
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKTanitoVezgettseg_AlkalmazottId_IntezmenyId') BEGIN
CREATE INDEX NCI_KKTanitoVezgettseg_AlkalmazottId_IntezmenyId 
  ON T_KKTANITOVEZGETTSEG (
     C_ALKALMAZOTTID
    ,C_INTEZMENYID
  )
  INCLUDE (C_KKTANIOTOMUVTERTIPUSID,TOROLT,LASTCHANGED,MODIFIER,ELOZOTANEVIREKORDID)
  WITH (FILLFACTOR = 80)
END
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKTanitoVezgettseg_ElozotanevirekordId') BEGIN
CREATE INDEX NCI_KKTanitoVezgettseg_ElozotanevirekordId
  ON T_KKTANITOVEZGETTSEG (
    ELOZOTANEVIREKORDID
  )
  INCLUDE (C_INTEZMENYID)
  WITH (FILLFACTOR = 80)
END  
-- ==================================
-- T_KKTANTARGYKATEGORIA
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKTantargyKategoria_KKTanarVegzettsegId_IntezmenyId') BEGIN
CREATE INDEX NCI_KKTantargyKategoria_KKTanarVegzettsegId_IntezmenyId
  ON T_KKTANTARGYKATEGORIA (
      C_KKTANARVEGZETTSEGID
     ,C_INTEZMENYID
  )
  INCLUDE(C_KKSZAKTIPUSID,TOROLT,SERIAL,ELOZOTANEVIREKORDID,LASTCHANGED,MODIFIER)
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_KKTantargyKategoria_IntezmenyId_ElozotaneviRekordId') BEGIN
CREATE INDEX NCI_KKTantargyKategoria_IntezmenyId_ElozotaneviRekordId
  ON T_KKTANTARGYKATEGORIA (
      C_KKTANARVEGZETTSEGID
   ,C_INTEZMENYID
  )
  INCLUDE (C_KKSZAKTIPUSID,TOROLT,SERIAL,LASTCHANGED,MODIFIER)
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_LOG
-- ==================================
ALTER INDEX ALL ON dbo.T_LOG
REBUILD
WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);
GO

-- ==================================
-- T_MUKODESIHELY
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Mukodesihely_ElozotanevirekordId') BEGIN
  CREATE INDEX NCI_Mukodesihely_ElozotanevirekordId
    ON T_MUKODESIHELY (ELOZOTANEVIREKORDID) 
    INCLUDE (C_INTEZMENYID)
    WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_NAPTARINAP
-- ==================================
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, C_HETSORSZAMA)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO  

-- ==================================
-- T_OLDALLATOGATOTTSAG
-- ==================================
IF INDEXPROPERTY(OBJECT_ID('dbo.T_OLDALLATOGATOTTSAG'), 'PK_OldalLatogatottsag', 'IsClustered') = 1
    BEGIN

    ALTER TABLE dbo.T_OLDALLATOGATOTTSAG
        DROP CONSTRAINT PK_OldalLatogatottsag;

    ALTER TABLE dbo.T_OLDALLATOGATOTTSAG
        ADD CONSTRAINT PK_OldalLatogatottsag PRIMARY KEY NONCLUSTERED (ID)
        WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100)

    END

IF INDEXPROPERTY(OBJECT_ID('dbo.T_OLDALLATOGATOTTSAG'), 'CCI_OldalLatogatottsag', 'IndexID') IS NULL
    CREATE CLUSTERED COLUMNSTORE INDEX CCI_OldalLatogatottsag ON dbo.T_OLDALLATOGATOTTSAG
    WITH (DATA_COMPRESSION = COLUMNSTORE_ARCHIVE);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_OLDALLATOGATOTTSAG'), 'NCI_OldalLatogatottsag_FelhasznaloId', 'IndexID') IS NOT NULL
    ALTER INDEX [NCI_OldalLatogatottsag_FelhasznaloId] ON dbo.T_OLDALLATOGATOTTSAG
    REBUILD
    WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_OLDALLATOGATOTTSAG'), 'NCI_OldalLatogatottsag_GondviseloId', 'IndexID') IS NOT NULL
    ALTER INDEX [NCI_OldalLatogatottsag_GondviseloId] ON dbo.T_OLDALLATOGATOTTSAG
    REBUILD
    WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_OLDALLATOGATOTTSAG'), 'NCI_OldalLatogatottsag_IntezmenyId', 'IndexID') IS NOT NULL
    ALTER INDEX [NCI_OldalLatogatottsag_IntezmenyId] ON dbo.T_OLDALLATOGATOTTSAG
    REBUILD
    WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

IF INDEXPROPERTY(OBJECT_ID('dbo.T_OLDALLATOGATOTTSAG'), 'NCI_OldalLatogatottsag_TanevId', 'IndexID') IS NOT NULL
    ALTER INDEX [NCI_OldalLatogatottsag_TanevId] ON dbo.T_OLDALLATOGATOTTSAG
    REBUILD
    WITH (DATA_COMPRESSION = PAGE, FILLFACTOR = 100);

GO

-- ==================================
-- T_ORARENDIORA
-- ==================================
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

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_OrarendiOra_IntezmenyId_TanevId_TantargyId_TanarId_HetirendId_Torolt') BEGIN
  CREATE NONCLUSTERED INDEX NCI_OrarendiOra_IntezmenyId_TanevId_TantargyId_TanarId_HetirendId_Torolt
    ON T_ORARENDIORA (
       C_INTEZMENYID
      ,C_TANEVID
      ,C_TANTARGYID
      ,C_TANARID
      ,C_HETIREND
      ,TOROLT
     )
    INCLUDE (C_HETNAPJA,C_ORASZAM,C_ORAERVENYESSEGKEZDETE,C_ORAERVENYESSEGVEGE,C_ORAKEZDETE,C_ORAVEGE,C_IMPORTALT,C_TEREMID,C_OSZTALYCSOPORTID)
    WHERE TOROLT='F'
    WITH (FILLFACTOR = 80)
END
GO

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

-- ==================================
-- T_ORATERV
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Oraterv_IntezmenyId_TanevId_Evfolyam_Nev') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_Oraterv_IntezmenyId_TanevId_Evfolyam_Nev
    ON dbo.T_ORATERV (C_INTEZMENYID , C_TANEVID , C_EVFOLYAM, C_NEV)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END

-- ==================================
-- T_OSZTALYCSOPORT
-- ==================================
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_EvfolyamTipusa') BEGIN
  CREATE NONCLUSTERED INDEX NCI_OsztalyCsoport_TanevId_IntezmenyId_EvfolyamTipusa
    ON dbo.T_OSZTALYCSOPORT (C_TANEVID,C_INTEZMENYID,C_EVFOLYAMTIPUSA)
  INCLUDE (C_NEV,C_VEGZOSEVFOLYAM,C_KERESZTFELEVES)
  WHERE TOROLT = 'F'
  WITH FILLFACTOR = 80
END
GO

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

-- ==================================
-- T_SZAMONKERESELOREJELZES
-- ==================================

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

-- TODO ERTEKELES REFAKT2 ERTEKELESMOD: Ha töröljük a T_TANARIATLAGSULY táblát, akkor törölni kell az NCI_TanariAtlagSuly_ErtekelesmodId_IntezmenyId_TanevId index-et!
-- https://jira.ekreta.hu/browse/KRETA2-12367
-- ==================================
-- T_TANARIATLAGSULY
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanariAtlagSuly_ErtekelesmodId_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanariAtlagSuly_ErtekelesmodId_IntezmenyId_TanevId
    ON T_TANARIATLAGSULY (C_ERTEKELESMODID, C_INTEZMENYID, C_TANEVID)
  INCLUDE (C_SULY)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TANEVRENDJE
-- ==================================
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, C_EGYEDINAP)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

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

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

-- ==================================
-- T_TANITASIORA
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Tanitasiora_OrarendioraId_IntezmenyId_TanevId') BEGIN
  CREATE INDEX NCI_Tanitasiora_OrarendioraId_IntezmenyId_TanevId 
    ON T_TANITASIORA(C_ORARENDIORAID, C_INTEZMENYID, C_TANEVID) 
  INCLUDE (C_MEGTARTOTT) 
  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_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_IntezmenyId_TanevId_TeremId') BEGIN
  CREATE INDEX NCI_TanitasiOra_IntezmenyId_TanevId_TeremId 
  ON T_TANITASIORA (C_INTEZMENYID, C_TANEVID, C_TEREMID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name='NCI_TanitasiOra_TanevId_IntezmenyId_Datum') BEGIN
  CREATE INDEX NCI_TanitasiOra_TanevId_IntezmenyId_Datum 
  ON T_TANITASIORA (
     C_TANEVID
    ,C_INTEZMENYID
    ,C_DATUM
  ) 
  INCLUDE(C_OSZTALYCSOPORTID, C_TANTARGYID, C_MEGTARTOTT)
  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_Datum_TanevId_IntezmenyId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_TanitasiOra_OsztalyCsoportId_Datum_TanevId_IntezmenyId
  ON dbo.T_TANITASIORA (
     C_OSZTALYCSOPORTID
    ,C_DATUM
    ,C_TANEVID
    ,C_INTEZMENYID
  )
  INCLUDE (C_CSENGETESIRENDID,C_TANTARGYID,C_ORASZAM,C_MEGTARTOTT)
  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_TanarId_Datum_TanevId') BEGIN
  CREATE INDEX NCI_TanitasiOra_TanarId_Datum_TanevId
    ON T_TANITASIORA (
       C_TANARID, C_DATUM, C_TANEVID
    )
    INCLUDE (C_INTEZMENYID, C_OSZTALYCSOPORTID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOra_OsztalyCsoportId_Datum_TanevId_IntezmenyId') BEGIN
  CREATE INDEX NCI_TanitasiOra_OsztalyCsoportId_Datum_TanevId_IntezmenyId
    ON T_TANITASIORA (
       C_OSZTALYCSOPORTID, C_DATUM, C_TANEVID, C_INTEZMENYID
    )
    INCLUDE (C_TANTARGYID) 
  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
    )
  INCLUDE(C_HELYETTESITESTIPUSA)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

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

IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCU_TanitasiOra_TanevId_IntezmenyId_Datum_OsztalyCsoportId_TantargyId_TanarId_Orakezdete_Oravege') BEGIN
CREATE UNIQUE INDEX NCU_TanitasiOra_TanevId_IntezmenyId_Datum_OsztalyCsoportId_TantargyId_TanarId_Orakezdete_Oravege ON T_TANITASIORA 
(
     C_TANEVID
    ,C_INTEZMENYID
    ,C_DATUM
    ,C_OSZTALYCSOPORTID
    ,C_TANTARGYID
    ,C_TANARID
    ,C_ORAKEZDETE
    ,C_ORAVEGE
)
WHERE TOROLT='F' AND C_ORASZAM IS NULL
WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCU_TanitasiOra_TanevId_IntezmenyId_Datum_OsztalyCsoportId_TantargyId_TanarId_Oraszam') BEGIN
CREATE UNIQUE INDEX NCU_TanitasiOra_TanevId_IntezmenyId_Datum_OsztalyCsoportId_TantargyId_TanarId_Oraszam ON T_TANITASIORA 
(
     C_TANEVID
    ,C_INTEZMENYID
    ,C_DATUM
    ,C_OSZTALYCSOPORTID
    ,C_TANTARGYID
    ,C_TANARID
    ,C_ORASZAM
)
WHERE TOROLT='F' AND C_ORASZAM IS NOT NULL
WITH (FILLFACTOR = 80)
END
GO

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
GO

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

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOra_IntezmenyId_TanevId') BEGIN
  CREATE NONCLUSTERED INDEX [NCI_TanitasiOra_IntezmenyId_TanevId_Datum_OsztalycsoportId_TantargyId] ON [dbo].[T_TANITASIORA]
  (
      [C_TANEVID] ASC,
      [C_INTEZMENYID] ASC,
      [C_DATUM] ASC,
      [C_OSZTALYCSOPORTID] ASC,
      [C_TANTARGYID] ASC,
      [C_TANARID] ASC
  )
  INCLUDE([C_HELYETTESITOTANARID], [C_ORASZAM], [C_ORAKEZDETE], [C_ORAVEGE]) 
  WHERE ([TOROLT] = 'F')
END
GO

-- ==================================
-- T_TANMENET
-- ==================================
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_TANTARGY
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Tantargy_IntezmenyId_TanevId_TargyKategoria') BEGIN
  CREATE INDEX NCI_Tantargy_IntezmenyId_TanevId_TargyKategoria 
    ON T_TANTARGY (C_INTEZMENYID,C_TANEVID,C_TARGYKATEGORIA) 
  INCLUDE (C_NEV, C_ROVIDNEV, C_GYAKORLATI)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
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_GYAKORLATI, C_NEV, C_ROVIDNEV, C_TANEVID, C_TARGYKATEGORIA)
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TANTERV
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Tanterv_Vedett_TanevId_IntezmenyId') BEGIN
  CREATE INDEX NCU_Tanterv_Vedett_TanevId_IntezmenyId
  ON T_TANTERV (
     C_VEDETT
    ,C_TANEVID
    ,C_INTEZMENYID)
  WHERE TOROLT='F' AND C_VEDETT='T'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TANULO
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Tanulo_AlintezmenyId_AltanevId') BEGIN
  CREATE INDEX NCI_Tanulo_AlintezmenyId_AltanevId 
    ON T_TANULO (C_ALINTEZMENYID, C_ALTANEVID) 
    WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TANULOCSOPORT
-- ==================================
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_TanuloId_OsztalyCsoportId_TanevId_IntezmenyId') BEGIN
CREATE INDEX NCI_TanuloCsoport_TanuloId_OsztalyCsoportId_TanevId_IntezmenyId 
  ON T_TANULOCSOPORT (
     C_TANULOID
    ,C_OSZTALYCSOPORTID
    ,C_TANEVID
    ,C_INTEZMENYID
  ) 
  INCLUDE (C_KILEPESDATUM, C_BELEPESDATUM) 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

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name='NCI_TanuloCsoport_IntezmenyId_TanevId_TanuloId') BEGIN
  CREATE NONCLUSTERED INDEX [NCI_TanuloCsoport_IntezmenyId_TanevId_TanuloId] ON [dbo].[T_TANULOCSOPORT]
  (
	  [C_INTEZMENYID] ASC,
	  [C_TANEVID] ASC,
	  [C_TANULOID] ASC
  )
  INCLUDE([C_OSZTALYCSOPORTID], [C_BELEPESDATUM], [C_KILEPESDATUM]) 
  WHERE ([TOROLT] = 'F')
  WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
END

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name='NCI_OsztalyCsoport_IntezmenyId_TanevId_FeladatKategoriaId') BEGIN
  CREATE INDEX NCI_OsztalyCsoport_IntezmenyId_TanevId_FeladatKategoriaId 
  ON T_OSZTALYCSOPORT (
     C_INTEZMENYID
    ,C_TANEVID
    ,C_FELADATKATEGORIAID
  ) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TANULOERTEKELES
-- ==================================
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,C_MAGATARTASERTEKID,C_MAGATARTASOSZTALYZATID,C_DATUM,C_OSZTALYCSOPORTID,C_SZORGALOMERTEKID,C_SZORGALOMOSZTALYZATID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloErtekeles_OsszefuggoSzakgyakId_IntezmenyId_TanevId') BEGIN
  CREATE INDEX NCI_TanuloErtekeles_OsszefuggoSzakgyakId_IntezmenyId_TanevId
    ON T_TANULOERTEKELES (C_OSSZEFUGGOSZAKGYAKID, C_INTEZMENYID, C_TANEVID) 
  INCLUDE (C_ERTEKELESOSZTALYZATID) 
  WHERE TOROLT = 'F' 
    AND C_OSSZEFUGGOSZAKGYAKID IS NOT NULL
  WITH (FILLFACTOR = 80)
END
GO

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloErtekeles_TanuloId_OsztalyCsoportId_Datum_TanevId_IntezmenyId_TipusId_ErtekelesOsztalyzatId') BEGIN
  CREATE INDEX NCI_TanuloErtekeles_TanuloId_OsztalyCsoportId_Datum_TanevId_IntezmenyId_TipusId_ErtekelesOsztalyzatId
  ON dbo.T_TANULOERTEKELES (
     C_TANULOID
    ,C_OSZTALYCSOPORTID
    ,C_DATUM
    ,C_TANEVID
    ,C_INTEZMENYID
    ,C_TIPUSID
    ,C_ERTEKELESOSZTALYZATID
  )
  INCLUDE (C_ERTEKELESMODID, C_ROGZITESKORITANULOOSZTALYID, C_TANTARGYID,C_ERTEKELESSZAZALEK,C_ERTEKELESSZOVEG,C_ERTEKELESSZOVEGROVIDNEV,C_ERTEKELESTEMA
          ,C_MAGATARTASERTEKID,C_MAGATARTASOSZTALYZATID,C_MAGATARTASSZOVEGROVIDNEV,C_SZORGALOMERTEKID,C_SZORGALOMOSZTALYZATID,C_SZORGALOMSZOVEGROVIDNEV) 
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanuloErtekeles_TanevId_ErtekelesModId_IntezmenyId_ErtekelesOsztalyzatId') BEGIN
  CREATE INDEX NCI_TanuloErtekeles_TanevId_ErtekelesModId_IntezmenyId_ErtekelesOsztalyzatId ON T_TANULOERTEKELES (
     C_TANEVID
    ,C_ERTEKELESMODID
    ,C_INTEZMENYID
    ,C_ERTEKELESOSZTALYZATID
  )
  INCLUDE (C_DATUM,C_OSZTALYCSOPORTID,C_TANTARGYID,C_ERTEKELESTEMA)
  WHERE TOROLT='F'
    AND C_ERTEKELESTEMA IS NOT NULL
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TANULOESEMENY
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_TanuloEsemeny_TanitasiOraId_Tipus_BeirasTanuloId') BEGIN
CREATE UNIQUE NONCLUSTERED INDEX NCU_TanuloEsemeny_TanitasiOraId_Tipus_BeirasTanuloId 
  ON dbo.T_TANULOESEMENY (C_TANITASIORAID, C_TIPUS, C_BEIRASTANULOID) 
WHERE C_TANITASIORAID IS NOT NULL 
  AND C_BEIRASTANULOID IS NOT NULL 
  AND TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TANULOMENTESSEG
-- ==================================
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
GO

-- ==================================
-- T_TANULOMULASZTAS
-- ==================================
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
    ,C_IGAZOLT
  )
  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
    ,C_IGAZOLT
  )
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name='NCU_TanuloMulasztas_OratanuloiId_TanitasiOrakid') BEGIN
CREATE UNIQUE INDEX NCU_TanuloMulasztas_OratanuloiId_TanitasiOrakid
ON T_TANULOMULASZTAS(
   C_ORATANULOIID
  ,C_TANITASIORAKID
  )
WHERE TOROLT='F'
WITH (FILLFACTOR = 80)
END
GO

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

-- ==================================
-- T_TANULOSNI
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name='NCU_TanuloSni_TanuloId_IntezmenyId_TanevId') BEGIN
  CREATE UNIQUE INDEX NCU_TanuloSni_TanuloId_IntezmenyId_TanevId 
  ON T_TANULOSNI (C_TANULOID, C_INTEZMENYID, C_TANEVID) 
  WHERE TOROLT = 'F'
WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TELEFON
-- ==================================
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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Telefon_ElozotanevirekordId') BEGIN
  CREATE NONCLUSTERED INDEX NCI_Telefon_ElozotanevirekordId
    ON T_TELEFON (ELOZOTANEVIREKORDID)
  INCLUDE (C_INTEZMENYID)
  WITH (FILLFACTOR = 80)  
END
GO

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Telefon_FelhasznaloId_GondviseloId_TanevId') BEGIN
  CREATE UNIQUE INDEX NCU_Telefon_FelhasznaloId_GondviseloId_TanevId
    ON T_TELEFON (
      C_FELHASZNALOID
      ,C_GONDVISELOID
      ,C_TANEVID)
    WHERE TOROLT = 'F' AND C_ALAPERTELMEZETT = 'T'
END
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Telefon_FelhasznaloId_GondviseloId_TanevId_Telefonszam') BEGIN
  CREATE UNIQUE INDEX NCU_Telefon_FelhasznaloId_GondviseloId_TanevId_Telefonszam
     ON T_TELEFON (
        C_FELHASZNALOID
       ,C_GONDVISELOID
       ,C_TANEVID
       ,C_TELEFONSZAM
	     ,C_ISPUBLIC)
     WHERE TOROLT = 'F' 
END
GO
​
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Telefon_FelhasznaloId_TanevId') BEGIN
  CREATE UNIQUE INDEX NCU_Telefon_FelhasznaloId_TanevId
     ON T_TELEFON (
        C_FELHASZNALOID
       ,C_TANEVID)
     WHERE
       TOROLT = 'F' 
       AND C_ISPUBLIC = 'T' 
       AND C_GONDVISELOID IS NULL
END
GO

-- ==================================
-- T_TEREM
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Terem_IntezmenyId_TanevId_Nev_SzervezetId') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_Terem_IntezmenyId_TanevId_Nev_SzervezetId
    ON dbo.T_TEREM (C_INTEZMENYID , C_TANEVID , C_NEV, C_SZERVEZETID)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END

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

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_Terem_ElozotanevirekordId_IntezmenyId') BEGIN
  CREATE INDEX NCI_Terem_ElozotanevirekordId_IntezmenyId
    ON T_TEREM (ELOZOTANEVIREKORDID,C_INTEZMENYID) 
    INCLUDE (C_JELLEG,C_NEV,C_TEREMFELELOSID,C_MUKODESIHELYID,SERIAL,TOROLT)
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TEREM_FELTOLTOTTFAJL
-- ==================================
ALTER TABLE T_TEREM_FELTOLTOTTFAJL DROP CONSTRAINT IF EXISTS FK_Terem_FeltoltottFajl_FeltoltottFajlId_REF_FeltoltottFajl;   
GO

ALTER TABLE T_TEREM_FELTOLTOTTFAJL DROP CONSTRAINT IF EXISTS FK_Terem_FeltoltottFajl_TeremId_REF_Terem;   
GO

ALTER TABLE T_TEREM_FELTOLTOTTFAJL DROP CONSTRAINT IF EXISTS PK_Terem_FeltoltottFajl;   
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'CU_Terem_FeltoltottFajl_TeremId_FeltoltottFajlId') BEGIN
  CREATE UNIQUE CLUSTERED INDEX CU_Terem_FeltoltottFajl_TeremId_FeltoltottFajlId
    ON T_TEREM_FELTOLTOTTFAJL (C_TEREMID, C_FELTOLTOTTFAJLID)
  WITH (FILLFACTOR = 80)  
END
GO

IF OBJECT_ID('PK_Terem_FeltoltottFajl') IS NULL BEGIN
  ALTER TABLE T_TEREM_FELTOLTOTTFAJL 
  ADD CONSTRAINT PK_Terem_FeltoltottFajl PRIMARY KEY (ID);   
END
GO

IF OBJECT_ID('FK_Terem_FeltoltottFajl_FeltoltottFajlId_REF_FeltoltottFajl', 'F') IS NULL BEGIN
ALTER TABLE [DBO].T_TEREM_FELTOLTOTTFAJL 
  ADD CONSTRAINT FK_Terem_FeltoltottFajl_FeltoltottFajlId_REF_FeltoltottFajl 
  FOREIGN KEY (C_FELTOLTOTTFAJLID) 
  REFERENCES [DBO].T_FELTOLTOTTFAJL (ID)
END
GO

IF OBJECT_ID('FK_Terem_FeltoltottFajl_TeremId_REF_Terem', 'F') IS NULL BEGIN
ALTER TABLE [DBO].T_TEREM_FELTOLTOTTFAJL 
  ADD CONSTRAINT FK_Terem_FeltoltottFajl_TeremId_REF_Terem 
  FOREIGN KEY (C_TEREMID) 
  REFERENCES [DBO].T_TEREM (ID)
END
GO 

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_Terem_FeltoltottFajl_TeremId') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_Terem_FeltoltottFajl_TeremId
    ON T_TEREM_FELTOLTOTTFAJL (C_TEREMID)
  WHERE C_ISDOKUMENTUM = 'T'
  WITH (FILLFACTOR = 80)  
END
GO

-- ==================================
-- T_USERPROFILE
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_UserProfile_FelhasznaloId') BEGIN
  CREATE INDEX NCU_UserProfile_FelhasznaloId
  ON T_USERPROFILE (
     C_FELHASZNALOID
  )
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_TANITASIORATULAJDONSAG
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_TanitasiOraTulajdonsag_IntezmenyId_TanevId_TanitasioraId_OraTulajdonsagId')
    CREATE NONCLUSTERED INDEX NCI_TanitasiOraTulajdonsag_IntezmenyId_TanevId_TanitasioraId_OraTulajdonsagId
    ON T_TANITASIORATULAJDONSAG(
        C_INTEZMENYID, 
        C_TANEVID, 
        C_TANITASIORAID, 
        C_ORATULAJDONSAGID
    )
    INCLUDE(TOROLT)
    WITH (FILLFACTOR = 80)
GO

-- ==================================
-- T_ORASORSZAMOZASHALMAZOSSZEREN
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCUI_OraSorszamozasHalmazOsszeren_TantargyId_OsztalyCsoportId')
  CREATE UNIQUE NONCLUSTERED INDEX [NCUI_OraSorszamozasHalmazOsszeren_TantargyId_OsztalyCsoportId]
  ON T_ORASORSZAMOZASHALMAZOSSZEREN(C_TANTARGYID, C_OSZTALYCSOPORTID)
  WHERE (TOROLT = 'F')
  WITH (FILLFACTOR = 80);
GO

-- ==================================
-- T_INTEZMENYADATOK
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_IntezmenyAdatok_IntezmenyId_TanevId_KozteruletJelleg')
BEGIN
  CREATE NONCLUSTERED INDEX [NCI_IntezmenyAdatok_IntezmenyId_TanevId_KozteruletJelleg] 
  ON [dbo].[T_INTEZMENYADATOK]
  (
    [C_INTEZMENYID] ASC,
    [C_TANEVID] ASC,
    [C_KOZTERULETJELLEGENEV] ASC
  )
END
GO

-- ==================================
-- T_MUKODESIHELY
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_MukodesiHely_IntezmenyId_TanevId_KozteruletJelleg')
BEGIN
  CREATE NONCLUSTERED INDEX [NCI_MukodesiHely_IntezmenyId_TanevId_KozteruletJelleg] 
  ON [dbo].[T_MUKODESIHELY]
  (
    [C_INTEZMENYID] ASC,
    [C_TANEVID] ASC,
    [C_KOZTERULETJELLEGENEV] ASC
  )
END
GO

-- ==================================
-- T_DKT_FELADAT
-- ==================================
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCI_DKT_Feladat_IntezmenyId_TanevId_FeladatTipusId')
BEGIN
  CREATE NONCLUSTERED INDEX [NCI_DKT_Feladat_IntezmenyId_TanevId_FeladatTipusId] 
  ON [dbo].[T_DKT_FELADAT]
  (
	  [C_INTEZMENYID] ASC,
	  [C_TANEVID] ASC,
	  [C_FELADATTIPUSID] ASC
  )
INCLUDE([C_DATUM],[C_BEADASHATARIDO],[C_IDOPONT],[C_LATHATOSAGIDOPONT],[C_ORASZAM],[C_TANITASIORAID],[C_TANTARGYID],[C_OSZTALYCSOPORTID],[C_ALKALMAZOTTID])
WHERE (TOROLT = 'F')
WITH (FILLFACTOR = 80)
END
GO

-- ==================================
-- T_ERTEKELESMAGSZORNYELV
-- ==================================
IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCUI_ErtekelesMagSzorNyelv_IntezmenyId_TanevId_NyelvId_ErtekelesMagSzorId')
BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX [NCUI_ErtekelesMagSzorNyelv_IntezmenyId_TanevId_NyelvId_ErtekelesMagSzorId] 
  ON [dbo].[T_ERTEKELESMAGSZORNYELV]
  (
	  C_INTEZMENYID,
    C_TANEVID,
    C_NYELVID,
    C_ERTEKELESMAGSZORID
  )
  WHERE (TOROLT = 'F')
  WITH (FILLFACTOR = 80)
END

-- ==================================
-- T_ERTEKELESTANTARGYINYELV
-- ==================================
IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCUI_ErtekelesTantargyiNyelv_IntezmenyId_TanevId_NyelvId_ErtekelesTantargyiId')
BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX [NCUI_ErtekelesTantargyiNyelv_IntezmenyId_TanevId_NyelvId_ErtekelesTantargyiId] 
  ON [dbo].[T_ERTEKELESTANTARGYINYELV]
  (
	  C_INTEZMENYID,
    C_TANEVID,
    C_NYELVID,
    C_ERTEKELESTANTARGYIID
  )
  WHERE (TOROLT = 'F')
  WITH (FILLFACTOR = 80)
END

-- ==================================
-- T_TANEV
-- ==================================
IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCI_Tanev_IntezmenyId2')
BEGIN
  CREATE NONCLUSTERED INDEX [NCI_Tanev_IntezmenyId2] 
  ON [dbo].[T_TANEV](C_INTEZMENYID)
  WHERE (TOROLT = 'F' AND C_AKTIV = 'T')
  WITH (FILLFACTOR = 100)
END

-- ==================================
-- T_SZERVEZET
-- ==================================
IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE name = 'NCU_Szervezet_Azonosito_Nev')
BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_Szervezet_Azonosito_Nev
  ON dbo.T_SZERVEZET(C_INTEZMENYID, C_TANEVID, C_AZONOSITO, C_NEV)
  WHERE (TOROLT = 'F')
  WITH (FILLFACTOR = 80)
END

-- ==================================================================================================================================
-- END CUSTOM INDEXES
-- ==================================================================================================================================
