﻿GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;

SET NUMERIC_ROUNDABORT OFF;


GO
/*
The column C_ORAKEZDETE on table [dbo].[T_ORARENDIORA] must be changed from NULL to NOT NULL. If the table contains data, the ALTER script may not work. To avoid this issue, you must add values to this column for all rows or mark it as allowing NULL values, or enable the generation of smart-defaults as a deployment option.

The column C_ORAVEGE on table [dbo].[T_ORARENDIORA] must be changed from NULL to NOT NULL. If the table contains data, the ALTER script may not work. To avoid this issue, you must add values to this column for all rows or mark it as allowing NULL values, or enable the generation of smart-defaults as a deployment option.
*/


GO
PRINT N'Dropping [dbo].[T_ORARENDIORA].[I_T_4025691_4025689]...';


GO
DROP INDEX [I_T_4025691_4025689]
    ON [dbo].[T_ORARENDIORA];


GO
PRINT N'Dropping [dbo].[T_TANITASIORA].[I_T_4025693_4025692]...';


GO
DROP INDEX [I_T_4025693_4025692]
    ON [dbo].[T_TANITASIORA];

GO
PRINT N'Dropping [dbo].[FK_4025620_4025619]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025620_4025619];


GO
PRINT N'Dropping [dbo].[FK_4025550_4025549]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4025550_4025549];


GO
PRINT N'Dropping [dbo].[FK_4025554_4025552]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4025554_4025552];


GO
PRINT N'Dropping [dbo].[FK_4025691_4025689]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4025691_4025689];


GO
PRINT N'Dropping [dbo].[FK_4026321_4026319]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4026321_4026319];


GO
PRINT N'Dropping [dbo].[FK_4026324_4026322]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4026324_4026322];


GO
PRINT N'Dropping [dbo].[FK_4026327_4026325]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4026327_4026325];


GO
PRINT N'Dropping [dbo].[FK_4026329_4026328]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4026329_4026328];


GO
PRINT N'Dropping [dbo].[FK_402553002_402553000]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_402553002_402553000];


GO
PRINT N'Dropping [dbo].[FK_402553005_402553003]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_402553005_402553003];


GO
PRINT N'Dropping [dbo].[FK_4025530_4025533]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4025530_4025533];


GO
PRINT N'Dropping [dbo].[FK_4025530_4025534]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4025530_4025534];


GO
PRINT N'Dropping [dbo].[FK_4026290_4026289]...';


GO
ALTER TABLE [dbo].[T_HELYETTESITESIIDOSZAK] DROP CONSTRAINT [FK_4026290_4026289];


GO
PRINT N'Dropping [dbo].[FK_4025938_4025937]...';


GO
ALTER TABLE [dbo].[T_TANULOERTEKELES] DROP CONSTRAINT [FK_4025938_4025937];


GO
PRINT N'Dropping [dbo].[FK_4025602_4025601]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025602_4025601];


GO
PRINT N'Dropping [dbo].[FK_4025608_4025607]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025608_4025607];


GO
PRINT N'Dropping [dbo].[FK_4025611_4025610]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025611_4025610];


GO
PRINT N'Dropping [dbo].[FK_4025623_4025622]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025623_4025622];


GO
PRINT N'Dropping [dbo].[FK_4025629_4025628]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025629_4025628];


GO
PRINT N'Dropping [dbo].[FK_4025635_4025634]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025635_4025634];


GO
PRINT N'Dropping [dbo].[FK_4025638_4025637]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025638_4025637];


GO
PRINT N'Dropping [dbo].[FK_4025693_4025692]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025693_4025692];


GO
PRINT N'Dropping [dbo].[FK_4026315_4026314]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4026315_4026314];


GO
PRINT N'Dropping [dbo].[FK_402557502_402557500]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_402557502_402557500];


GO
PRINT N'Dropping [dbo].[FK_402557505_402557503]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_402557505_402557503];


GO
PRINT N'Dropping [dbo].[FK_4025575_4025580]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025575_4025580];


GO
PRINT N'Dropping [dbo].[FK_4025575_4025581]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025575_4025581];


GO
PRINT N'Dropping [dbo].[FK_4025795_4025794]...';


GO
ALTER TABLE [dbo].[T_ORALATOGATAS] DROP CONSTRAINT [FK_4025795_4025794];


GO
PRINT N'Dropping [dbo].[FK_4027536_4027535]...';


GO
ALTER TABLE [dbo].[T_TANULOESEMENY] DROP CONSTRAINT [FK_4027536_4027535];


GO
PRINT N'Dropping [dbo].[FK_4025632_4025631]...';


GO
ALTER TABLE [dbo].[T_ORAK_TANAROK] DROP CONSTRAINT [FK_4025632_4025631];


GO
PRINT N'Dropping [dbo].[FK_4025674_4025672]...';


GO
ALTER TABLE [dbo].[T_TANULOMULASZTAS] DROP CONSTRAINT [FK_4025674_4025672];


GO
PRINT N'Starting rebuilding table [dbo].[T_ORARENDIORA]...';


GO
BEGIN TRANSACTION;

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

SET XACT_ABORT ON;

CREATE TABLE [dbo].[tmp_ms_xx_T_ORARENDIORA] (
    [ID]                         INT      IDENTITY (1, 1) NOT NULL,
    [C_DIFFERENCIALT]            CHAR (1) DEFAULT ('F') NULL,
    [C_DRAMA]                    CHAR (1) DEFAULT ('F') NULL,
    [C_HETIREND]                 INT      NOT NULL,
    [C_HETNAPJA]                 INT      NOT NULL,
    [C_IKTTANORA]                CHAR (1) DEFAULT ('F') NULL,
    [C_IPRTANORA]                CHAR (1) DEFAULT ('F') NULL,
    [C_KOOPERATIV]               CHAR (1) DEFAULT ('F') NULL,
    [C_MERES]                    CHAR (1) DEFAULT ('F') NULL,
    [C_MINDENNAPOSTESTNEVELES]   CHAR (1) DEFAULT ('F') NULL,
    [C_NEMSZAKRENDSZERUORA]      CHAR (1) DEFAULT ('F') NULL,
    [C_NEMZETISEGIORA]           CHAR (1) DEFAULT ('F') NULL,
    [C_ORASZAM]                  INT      NOT NULL,
    [C_SORSZAMOZANDO]            CHAR (1) DEFAULT ('T') NULL,
    [C_TAMOPORA]                 CHAR (1) DEFAULT ('F') NULL,
    [C_TULORA]                   CHAR (1) DEFAULT ('F') NULL,
    [C_BONTOTT]                  CHAR (1) NULL,
    [C_ORAERVENYESSEGKEZDETE]    DATETIME NOT NULL,
    [C_ORAERVENYESSEGVEGE]       DATETIME NULL,
    [C_PARHUZAMOSORA]            CHAR (1) DEFAULT ('F') NULL,
    [C_TIOP12]                   CHAR (1) DEFAULT ('F') NULL,
    [C_ORAKEZDETE]               DATETIME NOT NULL,
    [C_ORAVEGE]                  DATETIME NOT NULL,
    [C_TANORANKIVULIFOGLALKOZAS] CHAR (1) DEFAULT ('F') NULL,
    [C_IMPORTALT]                CHAR (1) DEFAULT ('F') NOT NULL,
    [C_CSENGETESIRENDID]         INT      NULL,
    [C_CSENGETESIRENDORAID]      INT      NULL,
    [C_TEREMID]                  INT      NULL,
    [C_FOGLALKOZASID]            INT      NULL,
    [C_TANTARGYID]               INT      NULL,
    [C_OSZTALYCSOPORTID]         INT      NULL,
    [C_TANARID]                  INT      NULL,
    [C_ORATULAJDONOSID]          INT      NULL,
    [C_INTEZMENYID]              INT      NOT NULL,
    [C_TANEVID]                  INT      NOT NULL,
    [TOROLT]                     CHAR (1) DEFAULT ('F') NULL,
    [SERIAL]                     INT      NULL,
    [LASTCHANGED]                DATETIME DEFAULT (getdate()) NULL,
    [CREATED]                    DATETIME DEFAULT (getdate()) NULL,
    [MODIFIER]                   INT      NULL,
    [CREATOR]                    INT      NULL,
    CONSTRAINT [tmp_ms_xx_constraint_PK_T_40255301] PRIMARY KEY CLUSTERED ([ID] ASC)
);

IF EXISTS (SELECT TOP 1 1 
           FROM   [dbo].[T_ORARENDIORA])
    BEGIN
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_ORARENDIORA] ON;
        INSERT INTO [dbo].[tmp_ms_xx_T_ORARENDIORA] ([ID], [C_DIFFERENCIALT], [C_DRAMA], [C_HETIREND], [C_HETNAPJA], [C_IKTTANORA], [C_IPRTANORA], [C_KOOPERATIV], [C_MERES], [C_MINDENNAPOSTESTNEVELES], [C_NEMSZAKRENDSZERUORA], [C_NEMZETISEGIORA], [C_ORASZAM], [C_SORSZAMOZANDO], [C_TAMOPORA], [C_TULORA], [C_BONTOTT], [C_ORAERVENYESSEGKEZDETE], [C_ORAERVENYESSEGVEGE], [C_PARHUZAMOSORA], [C_TIOP12], [C_ORAKEZDETE], [C_ORAVEGE], [C_TANORANKIVULIFOGLALKOZAS], [C_IMPORTALT], [C_TEREMID], [C_FOGLALKOZASID], [C_CSENGETESIRENDORAID], [C_TANTARGYID], [C_OSZTALYCSOPORTID], [C_TANARID], [C_ORATULAJDONOSID], [C_INTEZMENYID], [C_TANEVID], [TOROLT], [SERIAL], [LASTCHANGED], [CREATED], [MODIFIER], [CREATOR])
        SELECT   [ID],
                 [C_DIFFERENCIALT],
                 [C_DRAMA],
                 [C_HETIREND],
                 [C_HETNAPJA],
                 [C_IKTTANORA],
                 [C_IPRTANORA],
                 [C_KOOPERATIV],
                 [C_MERES],
                 [C_MINDENNAPOSTESTNEVELES],
                 [C_NEMSZAKRENDSZERUORA],
                 [C_NEMZETISEGIORA],
                 [C_ORASZAM],
                 [C_SORSZAMOZANDO],
                 [C_TAMOPORA],
                 [C_TULORA],
                 [C_BONTOTT],
                 [C_ORAERVENYESSEGKEZDETE],
                 [C_ORAERVENYESSEGVEGE],
                 [C_PARHUZAMOSORA],
                 [C_TIOP12],
                 [C_ORAKEZDETE],
                 [C_ORAVEGE],
                 [C_TANORANKIVULIFOGLALKOZAS],
                 [C_IMPORTALT],
                 [C_TEREMID],
                 [C_FOGLALKOZASID],
                 [C_CSENGETESIRENDORAID],
                 [C_TANTARGYID],
                 [C_OSZTALYCSOPORTID],
                 [C_TANARID],
                 [C_ORATULAJDONOSID],
                 [C_INTEZMENYID],
                 [C_TANEVID],
                 [TOROLT],
                 [SERIAL],
                 [LASTCHANGED],
                 [CREATED],
                 [MODIFIER],
                 [CREATOR]
        FROM     [dbo].[T_ORARENDIORA]
        ORDER BY [ID] ASC;
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_ORARENDIORA] OFF;
    END

DROP TABLE [dbo].[T_ORARENDIORA];

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_T_ORARENDIORA]', N'T_ORARENDIORA';

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_constraint_PK_T_40255301]', N'PK_T_4025530', N'OBJECT';

COMMIT TRANSACTION;

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_4025530_4025533]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025530_4025533]
    ON [dbo].[T_ORARENDIORA]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_HETIREND] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_4025530_4025534]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025530_4025534]
    ON [dbo].[T_ORARENDIORA]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_HETNAPJA] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_4025550_4025549]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025550_4025549]
    ON [dbo].[T_ORARENDIORA]([C_TEREMID] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_4025554_4025552]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025554_4025552]
    ON [dbo].[T_ORARENDIORA]([C_FOGLALKOZASID] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_4026321_4026319]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4026321_4026319]
    ON [dbo].[T_ORARENDIORA]([C_TANTARGYID] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_4026324_4026322]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4026324_4026322]
    ON [dbo].[T_ORARENDIORA]([C_OSZTALYCSOPORTID] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_4026327_4026325]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4026327_4026325]
    ON [dbo].[T_ORARENDIORA]([C_TANARID] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_4026329_4026328]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4026329_4026328]
    ON [dbo].[T_ORARENDIORA]([C_ORATULAJDONOSID] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_402553002_402553000]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402553002_402553000]
    ON [dbo].[T_ORARENDIORA]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_ORARENDIORA].[I_T_402553005_402553003]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402553005_402553003]
    ON [dbo].[T_ORARENDIORA]([C_TANEVID] ASC);


GO
PRINT N'Starting rebuilding table [dbo].[T_TANITASIORA]...';


GO
BEGIN TRANSACTION;

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

SET XACT_ABORT ON;

CREATE TABLE [dbo].[tmp_ms_xx_T_TANITASIORA] (
    [ID]                         INT             IDENTITY (1, 1) NOT NULL,
    [C_BEJEGYZESIDEJE]           DATETIME        NOT NULL,
    [C_BONTOTT]                  CHAR (1)        DEFAULT ('F') NULL,
    [C_DATUM]                    DATETIME        NOT NULL,
    [C_HELYETTESITESOKA]         NVARCHAR (255)  NULL,
    [C_HELYETTESITESTIPUSA]      INT             NULL,
    [C_HETNAPJA]                 INT             NOT NULL,
    [C_HETSORSZAMA]              INT             NOT NULL,
    [C_IKTTANORA]                CHAR (1)        DEFAULT ('F') NULL,
    [C_MEGJEGYZES]               NVARCHAR (255)  NULL,
    [C_MEGTARTOTT]               CHAR (1)        DEFAULT ('T') NULL,
    [C_NAPSORSZAMA]              INT             NOT NULL,
    [C_NEMSZAKRENDSZERUORA]      CHAR (1)        DEFAULT ('F') NULL,
    [C_ORAKEZDETE]               DATETIME        NOT NULL,
    [C_ORASZAM]                  INT             NOT NULL,
    [C_ORAVEGE]                  DATETIME        NOT NULL,
    [C_SORSZAMOZANDO]            CHAR (1)        NULL,
    [C_TAMOPORA]                 CHAR (1)        DEFAULT ('F') NULL,
    [C_TEMA]                     NVARCHAR (1000) NULL,
    [C_TULORA]                   CHAR (1)        DEFAULT ('F') NULL,
    [C_OSZTALYFONOKI]            CHAR (1)        DEFAULT ('F') NULL,
    [C_TANORANKIVULIFOGLALKOZAS] CHAR (1)        DEFAULT ('F') NULL,
    [C_HAZIFELADAT]              NVARCHAR (MAX)  NULL,
    [C_DIFFERENCIALT]            CHAR (1)        NULL,
    [C_DRAMA]                    CHAR (1)        NULL,
    [C_IPRTANORA]                CHAR (1)        NULL,
    [C_KOOPERATIV]               CHAR (1)        NULL,
    [C_MERES]                    CHAR (1)        NULL,
    [C_MINDENNAPOSTESTNEVELES]   CHAR (1)        NULL,
    [C_NEMZETISEGIORA]           CHAR (1)        NULL,
    [C_PARHUZAMOSORA]            CHAR (1)        NULL,
    [C_TIOP12]                   CHAR (1)        NULL,
    [C_ADMINALTALKIIRT]          CHAR (1)        NULL,
    [C_CSENGETESIRENDID]         INT             NULL,
    [C_CSENGETESIRENDORAID]      INT             NULL,
    [C_TANMENETID]               INT             NULL,
    [C_TANTARGYID]               INT             NULL,
    [C_NAPTARINAPID]             INT             NULL,
    [C_ORARENDIORAID]            INT             NULL,
    [C_FOGLALKOZASID]            INT             NULL,
    [C_HELYETTESITOTANARID]      INT             NULL,
    [C_TEREMID]                  INT             NULL,
    [C_OSZTALYCSOPORTID]         INT             NULL,
    [C_ORATULAJDONOSID]          INT             NOT NULL,
    [C_INTEZMENYID]              INT             NOT NULL,
    [C_TANEVID]                  INT             NOT NULL,
    [TOROLT]                     CHAR (1)        DEFAULT ('F') NULL,
    [SERIAL]                     INT             NULL,
    [LASTCHANGED]                DATETIME        DEFAULT (getdate()) NULL,
    [CREATED]                    DATETIME        DEFAULT (getdate()) NULL,
    [MODIFIER]                   INT             NULL,
    [CREATOR]                    INT             NULL,
    CONSTRAINT [tmp_ms_xx_constraint_PK_T_40255751] PRIMARY KEY CLUSTERED ([ID] ASC)
);

IF EXISTS (SELECT TOP 1 1 
           FROM   [dbo].[T_TANITASIORA])
    BEGIN
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_TANITASIORA] ON;
        INSERT INTO [dbo].[tmp_ms_xx_T_TANITASIORA] ([ID], [C_BEJEGYZESIDEJE], [C_BONTOTT], [C_DATUM], [C_HELYETTESITESOKA], [C_HELYETTESITESTIPUSA], [C_HETNAPJA], [C_HETSORSZAMA], [C_IKTTANORA], [C_MEGJEGYZES], [C_MEGTARTOTT], [C_NAPSORSZAMA], [C_NEMSZAKRENDSZERUORA], [C_ORAKEZDETE], [C_ORASZAM], [C_ORAVEGE], [C_SORSZAMOZANDO], [C_TAMOPORA], [C_TEMA], [C_TULORA], [C_OSZTALYFONOKI], [C_TANORANKIVULIFOGLALKOZAS], [C_HAZIFELADAT], [C_DIFFERENCIALT], [C_DRAMA], [C_IPRTANORA], [C_KOOPERATIV], [C_MERES], [C_MINDENNAPOSTESTNEVELES], [C_NEMZETISEGIORA], [C_PARHUZAMOSORA], [C_TIOP12], [C_ADMINALTALKIIRT], [C_TANMENETID], [C_TANTARGYID], [C_NAPTARINAPID], [C_ORARENDIORAID], [C_FOGLALKOZASID], [C_HELYETTESITOTANARID], [C_TEREMID], [C_OSZTALYCSOPORTID], [C_CSENGETESIRENDORAID], [C_ORATULAJDONOSID], [C_INTEZMENYID], [C_TANEVID], [TOROLT], [SERIAL], [LASTCHANGED], [CREATED], [MODIFIER], [CREATOR])
        SELECT   [ID],
                 [C_BEJEGYZESIDEJE],
                 [C_BONTOTT],
                 [C_DATUM],
                 [C_HELYETTESITESOKA],
                 [C_HELYETTESITESTIPUSA],
                 [C_HETNAPJA],
                 [C_HETSORSZAMA],
                 [C_IKTTANORA],
                 [C_MEGJEGYZES],
                 [C_MEGTARTOTT],
                 [C_NAPSORSZAMA],
                 [C_NEMSZAKRENDSZERUORA],
                 [C_ORAKEZDETE],
                 [C_ORASZAM],
                 [C_ORAVEGE],
                 [C_SORSZAMOZANDO],
                 [C_TAMOPORA],
                 [C_TEMA],
                 [C_TULORA],
                 [C_OSZTALYFONOKI],
                 [C_TANORANKIVULIFOGLALKOZAS],
                 [C_HAZIFELADAT],
                 [C_DIFFERENCIALT],
                 [C_DRAMA],
                 [C_IPRTANORA],
                 [C_KOOPERATIV],
                 [C_MERES],
                 [C_MINDENNAPOSTESTNEVELES],
                 [C_NEMZETISEGIORA],
                 [C_PARHUZAMOSORA],
                 [C_TIOP12],
                 [C_ADMINALTALKIIRT],
                 [C_TANMENETID],
                 [C_TANTARGYID],
                 [C_NAPTARINAPID],
                 [C_ORARENDIORAID],
                 [C_FOGLALKOZASID],
                 [C_HELYETTESITOTANARID],
                 [C_TEREMID],
                 [C_OSZTALYCSOPORTID],
                 [C_CSENGETESIRENDORAID],
                 [C_ORATULAJDONOSID],
                 [C_INTEZMENYID],
                 [C_TANEVID],
                 [TOROLT],
                 [SERIAL],
                 [LASTCHANGED],
                 [CREATED],
                 [MODIFIER],
                 [CREATOR]
        FROM     [dbo].[T_TANITASIORA]
        ORDER BY [ID] ASC;
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_TANITASIORA] OFF;
    END

DROP TABLE [dbo].[T_TANITASIORA];

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_T_TANITASIORA]', N'T_TANITASIORA';

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_constraint_PK_T_40255751]', N'PK_T_4025575', N'OBJECT';

COMMIT TRANSACTION;

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025575_4025580]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025575_4025580]
    ON [dbo].[T_TANITASIORA]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_HELYETTESITESTIPUSA] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025575_4025581]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025575_4025581]
    ON [dbo].[T_TANITASIORA]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_HETNAPJA] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025602_4025601]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025602_4025601]
    ON [dbo].[T_TANITASIORA]([C_TANMENETID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025608_4025607]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025608_4025607]
    ON [dbo].[T_TANITASIORA]([C_TANTARGYID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025611_4025610]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025611_4025610]
    ON [dbo].[T_TANITASIORA]([C_NAPTARINAPID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025620_4025619]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025620_4025619]
    ON [dbo].[T_TANITASIORA]([C_ORARENDIORAID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025623_4025622]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025623_4025622]
    ON [dbo].[T_TANITASIORA]([C_FOGLALKOZASID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025629_4025628]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025629_4025628]
    ON [dbo].[T_TANITASIORA]([C_HELYETTESITOTANARID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025635_4025634]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025635_4025634]
    ON [dbo].[T_TANITASIORA]([C_TEREMID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4025638_4025637]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025638_4025637]
    ON [dbo].[T_TANITASIORA]([C_OSZTALYCSOPORTID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_4026315_4026314]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4026315_4026314]
    ON [dbo].[T_TANITASIORA]([C_ORATULAJDONOSID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_402557502_402557500]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402557502_402557500]
    ON [dbo].[T_TANITASIORA]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_TANITASIORA].[I_T_402557505_402557503]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402557505_402557503]
    ON [dbo].[T_TANITASIORA]([C_TANEVID] ASC);


GO
PRINT N'Creating [dbo].[FK_4025620_4025619]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025620_4025619] FOREIGN KEY ([C_ORARENDIORAID]) REFERENCES [dbo].[T_ORARENDIORA] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025550_4025549]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025550_4025549] FOREIGN KEY ([C_TEREMID]) REFERENCES [dbo].[T_TEREM] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025554_4025552]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025554_4025552] FOREIGN KEY ([C_FOGLALKOZASID]) REFERENCES [dbo].[T_FOGLALKOZAS] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4026321_4026319]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4026321_4026319] FOREIGN KEY ([C_TANTARGYID]) REFERENCES [dbo].[T_TANTARGY] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4026324_4026322]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4026324_4026322] FOREIGN KEY ([C_OSZTALYCSOPORTID]) REFERENCES [dbo].[T_OSZTALYCSOPORT] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4026327_4026325]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4026327_4026325] FOREIGN KEY ([C_TANARID]) REFERENCES [dbo].[T_ALKALMAZOTT] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4026329_4026328]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4026329_4026328] FOREIGN KEY ([C_ORATULAJDONOSID]) REFERENCES [dbo].[T_FELHASZNALO] ([ID]);


GO
PRINT N'Creating [dbo].[FK_402553002_402553000]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_402553002_402553000] FOREIGN KEY ([C_INTEZMENYID]) REFERENCES [dbo].[T_INTEZMENY] ([ID]);


GO
PRINT N'Creating [dbo].[FK_402553005_402553003]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_402553005_402553003] FOREIGN KEY ([C_TANEVID]) REFERENCES [dbo].[T_TANEV] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025530_4025533]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025530_4025533] FOREIGN KEY ([C_HETIREND], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_HETIRENDTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


GO
PRINT N'Creating [dbo].[FK_4025530_4025534]...';


GO
ALTER TABLE [dbo].[T_ORARENDIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025530_4025534] FOREIGN KEY ([C_HETNAPJA], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_HETNAPJATIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


GO
PRINT N'Creating [dbo].[FK_4026290_4026289]...';


GO
ALTER TABLE [dbo].[T_HELYETTESITESIIDOSZAK] WITH NOCHECK
    ADD CONSTRAINT [FK_4026290_4026289] FOREIGN KEY ([C_HELYETTESITETTORARENDID]) REFERENCES [dbo].[T_ORARENDIORA] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025938_4025937]...';


GO
ALTER TABLE [dbo].[T_TANULOERTEKELES] WITH NOCHECK
    ADD CONSTRAINT [FK_4025938_4025937] FOREIGN KEY ([C_TANORAID]) REFERENCES [dbo].[T_TANITASIORA] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025602_4025601]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025602_4025601] FOREIGN KEY ([C_TANMENETID]) REFERENCES [dbo].[T_TANMENET] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025608_4025607]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025608_4025607] FOREIGN KEY ([C_TANTARGYID]) REFERENCES [dbo].[T_TANTARGY] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025611_4025610]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025611_4025610] FOREIGN KEY ([C_NAPTARINAPID]) REFERENCES [dbo].[T_NAPTARINAP] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025623_4025622]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025623_4025622] FOREIGN KEY ([C_FOGLALKOZASID]) REFERENCES [dbo].[T_FOGLALKOZAS] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025629_4025628]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025629_4025628] FOREIGN KEY ([C_HELYETTESITOTANARID]) REFERENCES [dbo].[T_ALKALMAZOTT] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025635_4025634]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025635_4025634] FOREIGN KEY ([C_TEREMID]) REFERENCES [dbo].[T_TEREM] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025638_4025637]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025638_4025637] FOREIGN KEY ([C_OSZTALYCSOPORTID]) REFERENCES [dbo].[T_OSZTALYCSOPORT] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4026315_4026314]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4026315_4026314] FOREIGN KEY ([C_ORATULAJDONOSID]) REFERENCES [dbo].[T_FELHASZNALO] ([ID]);


GO
PRINT N'Creating [dbo].[FK_402557502_402557500]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_402557502_402557500] FOREIGN KEY ([C_INTEZMENYID]) REFERENCES [dbo].[T_INTEZMENY] ([ID]);


GO
PRINT N'Creating [dbo].[FK_402557505_402557503]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_402557505_402557503] FOREIGN KEY ([C_TANEVID]) REFERENCES [dbo].[T_TANEV] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025575_4025580]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025575_4025580] FOREIGN KEY ([C_HELYETTESITESTIPUSA], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_HELYETTESITESTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


GO
PRINT N'Creating [dbo].[FK_4025575_4025581]...';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH NOCHECK
    ADD CONSTRAINT [FK_4025575_4025581] FOREIGN KEY ([C_HETNAPJA], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_HETNAPJATIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


GO
PRINT N'Creating [dbo].[FK_4025795_4025794]...';


GO
ALTER TABLE [dbo].[T_ORALATOGATAS] WITH NOCHECK
    ADD CONSTRAINT [FK_4025795_4025794] FOREIGN KEY ([C_MEGTARTOTTORAID]) REFERENCES [dbo].[T_TANITASIORA] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4027536_4027535]...';


GO
ALTER TABLE [dbo].[T_TANULOESEMENY] WITH NOCHECK
    ADD CONSTRAINT [FK_4027536_4027535] FOREIGN KEY ([C_TANITASIORAID]) REFERENCES [dbo].[T_TANITASIORA] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025632_4025631]...';


GO
ALTER TABLE [dbo].[T_ORAK_TANAROK] WITH NOCHECK
    ADD CONSTRAINT [FK_4025632_4025631] FOREIGN KEY ([C_ORAKID]) REFERENCES [dbo].[T_TANITASIORA] ([ID]);


GO
PRINT N'Creating [dbo].[FK_4025674_4025672]...';


GO
ALTER TABLE [dbo].[T_TANULOMULASZTAS] WITH NOCHECK
    ADD CONSTRAINT [FK_4025674_4025672] FOREIGN KEY ([C_TANITASIORAKID]) REFERENCES [dbo].[T_TANITASIORA] ([ID]);


GO
PRINT N'Refreshing [dbo].[T_ORARENDIORA_OSSZES]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[T_ORARENDIORA_OSSZES]';


GO
PRINT N'Refreshing [dbo].[T_TANITASIORA_OSSZES]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[T_TANITASIORA_OSSZES]';


GO
PRINT N'Checking existing data against newly created constraints';


GO
ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025620_4025619];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4025550_4025549];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4025554_4025552];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4026321_4026319];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4026324_4026322];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4026327_4026325];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4026329_4026328];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_402553002_402553000];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_402553005_402553003];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4025530_4025533];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4025530_4025534];

ALTER TABLE [dbo].[T_HELYETTESITESIIDOSZAK] WITH CHECK CHECK CONSTRAINT [FK_4026290_4026289];

ALTER TABLE [dbo].[T_TANULOERTEKELES] WITH CHECK CHECK CONSTRAINT [FK_4025938_4025937];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025602_4025601];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025608_4025607];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025611_4025610];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025623_4025622];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025629_4025628];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025635_4025634];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025638_4025637];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4026315_4026314];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_402557502_402557500];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_402557505_402557503];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025575_4025580];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025575_4025581];

ALTER TABLE [dbo].[T_ORALATOGATAS] WITH CHECK CHECK CONSTRAINT [FK_4025795_4025794];

ALTER TABLE [dbo].[T_TANULOESEMENY] WITH CHECK CHECK CONSTRAINT [FK_4027536_4027535];

ALTER TABLE [dbo].[T_ORAK_TANAROK] WITH CHECK CHECK CONSTRAINT [FK_4025632_4025631];

ALTER TABLE [dbo].[T_TANULOMULASZTAS] WITH CHECK CHECK CONSTRAINT [FK_4025674_4025672];


GO
PRINT N'Update complete.';


GO

PRINT '--- intézményi view-k (dbo táblákkal megegyező nevű és a tábla_OSSZES nevűek) frissítése ---'

DECLARE  @viewname nvarchar(100), @pureview nvarchar(100)

DECLARE semaviewk CURSOR LOCAL FOR 
  SELECT '['+TABLE_SCHEMA + '].[' + TABLE_NAME + ']', TABLE_NAME
  FROM INFORMATION_SCHEMA.TABLES
  WHERE TABLE_TYPE = 'VIEW' and TABLE_SCHEMA LIKE 'KR[_]%[_]Schema'
  AND TABLE_NAME in (
  'T_TANITASIORA', 'T_TANITASIORA_OSSZES',
  'T_ORARENDIORA', 'T_ORARENDIORA_OSSZES'
  ) -- ha csak néhány VIEW frissült, akkor a gyorsabb futásért ide fel lehet sorolni
  ORDER BY TABLE_SCHEMA, TABLE_NAME

OPEN semaviewk
FETCH NEXT FROM semaviewk INTO @viewname, @pureview

WHILE @@FETCH_STATUS = 0 BEGIN
	PRINT @viewname
	EXEC sp_refreshview @viewname

    FETCH NEXT FROM semaviewk INTO @viewname, @pureview
END             

CLOSE semaviewk
DEALLOCATE semaviewk
GO


-- Triggerek inicializálás az összes táblára
DECLARE tableCursor CURSOR LOCAL FOR 
  SELECT DISTINCT TABLE_NAME
  FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE COLUMN_NAME IN ('CREATOR', 'MODIFIER')
	AND TABLE_NAME NOT IN ('T_ENTITYHISTORY', 'T_ENTITYATTRIBUTEHISTORY', 'T_LOG', 'T_GLOBALLOCK', 'T_USERPROFILE', 'T_OLDALLATOGATOTTSAG')
	AND TABLE_NAME IN (
		SELECT t.name 
		FROM sys.tables t
		INNER JOIN sys.schemas s ON s.schema_id = t.schema_id
		WHERE s.name ='dbo' 
	)

DECLARE @table nvarchar(35)

OPEN tableCursor  
FETCH NEXT FROM tableCursor INTO @table  

WHILE @@FETCH_STATUS = 0 BEGIN  
  EXEC sp_Global_CreateTriggers @table
  FETCH NEXT FROM tableCursor INTO @table  
END  

CLOSE tableCursor  
DEALLOCATE tableCursor 


EXEC dev.sp_Global_GenerateAsyncAuditTriggerAll 1
GO

EXEC dev.sp_Global_GenerateAsyncAuditProcedureAll
GO

EXEC dev.sp_Global_GenerateAsyncAuditAuditPocessing
GO

ALTER QUEUE auditlog.AuditQueue WITH STATUS=OFF, ACTIVATION 
(STATUS = OFF)
GO

ALTER QUEUE auditlog.AuditQueue WITH STATUS=ON, ACTIVATION 
(STATUS = ON, MAX_QUEUE_READERS = 2)
GO
