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

SET NUMERIC_ROUNDABORT OFF;

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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] DROP CONSTRAINT [FK_4028120_4028118];


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] DROP CONSTRAINT [FK_4028123_4028121];


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] DROP CONSTRAINT [FK_4028126_4028124];


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] DROP CONSTRAINT [FK_4028129_4028127];


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] DROP CONSTRAINT [FK_402811202_402811200];


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] DROP CONSTRAINT [FK_402811205_402811203];


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


GO
BEGIN TRANSACTION;

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

SET XACT_ABORT ON;

CREATE TABLE [dbo].[tmp_ms_xx_T_HAZIFELADATOK] (
    [ID]                  INT            IDENTITY (1, 1) NOT NULL,
    [C_FELADASDATUMA]     DATETIME       NOT NULL,
    [C_HATARIDO]          DATETIME       NOT NULL,
    [C_FELADATSZOVEGE]    NVARCHAR (MAX) NOT NULL,
    [C_ORASZAM]           INT            NULL,
    [C_ISTANARROGZITETTE] CHAR (1)       NOT NULL,
    [C_TANTARGYID]        INT            NOT NULL,
    [C_ROGZITOID]         INT            NOT NULL,
    [C_OSZTALYCSOPORTID]  INT            NOT NULL,
    [C_TANITASIORAID]     INT            NULL,
    [C_HELYETTESITOID]    INT            NULL,
    [C_INTEZMENYID]       INT            NOT NULL,
    [C_TANEVID]           INT            NOT NULL,
    [TOROLT]              CHAR (1)       DEFAULT ('F') NOT NULL,
    [SERIAL]              INT            DEFAULT ((0)) NOT NULL,
    [LASTCHANGED]         DATETIME       DEFAULT (getdate()) NOT NULL,
    [CREATED]             DATETIME       DEFAULT (getdate()) NOT NULL,
    [MODIFIER]            INT            NULL,
    [CREATOR]             INT            NULL,
    [ELOZOTANEVIREKORDID] INT            NULL,
    [NNID]                INT            NULL,
    CONSTRAINT [tmp_ms_xx_constraint_PK_T_40281121] PRIMARY KEY CLUSTERED ([ID] ASC)
);

IF EXISTS (SELECT TOP 1 1 
           FROM   [dbo].[T_HAZIFELADATOK])
    BEGIN
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_HAZIFELADATOK] ON;
        INSERT INTO [dbo].[tmp_ms_xx_T_HAZIFELADATOK] ([ID], [C_FELADASDATUMA], [C_HATARIDO], [C_FELADATSZOVEGE], [C_ORASZAM], [C_ISTANARROGZITETTE], [C_TANTARGYID], [C_ROGZITOID], [C_OSZTALYCSOPORTID], [C_TANITASIORAID], [C_INTEZMENYID], [C_TANEVID], [TOROLT], [SERIAL], [LASTCHANGED], [CREATED], [MODIFIER], [CREATOR], [ELOZOTANEVIREKORDID], [NNID])
        SELECT   [ID],
                 [C_FELADASDATUMA],
                 [C_HATARIDO],
                 [C_FELADATSZOVEGE],
                 [C_ORASZAM],
                 [C_ISTANARROGZITETTE],
                 [C_TANTARGYID],
				 [C_FELHASZNALOID],
                 [C_OSZTALYCSOPORTID],
                 [C_TANITASIORAID],
                 [C_INTEZMENYID],
                 [C_TANEVID],
                 [TOROLT],
                 [SERIAL],
                 [LASTCHANGED],
                 [CREATED],
                 [MODIFIER],
                 [CREATOR],
                 [ELOZOTANEVIREKORDID],
                 [NNID]
        FROM     [dbo].[T_HAZIFELADATOK]
        ORDER BY [ID] ASC;
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_HAZIFELADATOK] OFF;
    END

DROP TABLE [dbo].[T_HAZIFELADATOK];

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_T_HAZIFELADATOK]', N'T_HAZIFELADATOK';

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_constraint_PK_T_40281121]', N'PK_T_4028112', N'OBJECT';

COMMIT TRANSACTION;

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;


GO
PRINT N'Creating [dbo].[T_HAZIFELADATOK].[I_T_4028120_4028118]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028120_4028118]
    ON [dbo].[T_HAZIFELADATOK]([C_TANTARGYID] ASC);


GO
PRINT N'Creating [dbo].[T_HAZIFELADATOK].[I_T_4028123_4028121]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028123_4028121]
    ON [dbo].[T_HAZIFELADATOK]([C_ROGZITOID] ASC);


GO
PRINT N'Creating [dbo].[T_HAZIFELADATOK].[I_T_4028126_4028124]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028126_4028124]
    ON [dbo].[T_HAZIFELADATOK]([C_OSZTALYCSOPORTID] ASC);


GO
PRINT N'Creating [dbo].[T_HAZIFELADATOK].[I_T_4028129_4028127]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028129_4028127]
    ON [dbo].[T_HAZIFELADATOK]([C_TANITASIORAID] ASC);


GO
PRINT N'Creating [dbo].[T_HAZIFELADATOK].[I_T_4028276_4028274]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028276_4028274]
    ON [dbo].[T_HAZIFELADATOK]([C_HELYETTESITOID] ASC);


GO
PRINT N'Creating [dbo].[T_HAZIFELADATOK].[I_T_402811202_402811200]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402811202_402811200]
    ON [dbo].[T_HAZIFELADATOK]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_HAZIFELADATOK].[I_T_402811205_402811203]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402811205_402811203]
    ON [dbo].[T_HAZIFELADATOK]([C_TANEVID] ASC);


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


GO
CREATE TABLE [dbo].[T_TANULOHAZIFELADAT] (
    [ID]                  INT            IDENTITY (1, 1) NOT NULL,
    [C_BEJELENTESDATUMA]  DATETIME       NOT NULL,
    [C_FELADATSZOVEGE]    NVARCHAR (MAX) NOT NULL,
    [C_HAZIFELADATID]     INT            NOT NULL,
    [C_ROGZITOID]         INT            NOT NULL,
    [C_INTEZMENYID]       INT            NOT NULL,
    [C_TANEVID]           INT            NOT NULL,
    [TOROLT]              CHAR (1)       NOT NULL,
    [SERIAL]              INT            NOT NULL,
    [LASTCHANGED]         DATETIME       NOT NULL,
    [CREATED]             DATETIME       NOT NULL,
    [MODIFIER]            INT            NULL,
    [CREATOR]             INT            NULL,
    [ELOZOTANEVIREKORDID] INT            NULL,
    [NNID]                INT            NULL,
    CONSTRAINT [PK_T_4028271] PRIMARY KEY CLUSTERED ([ID] ASC)
);


GO
PRINT N'Creating [dbo].[T_TANULOHAZIFELADAT].[I_T_4028279_4028277]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028279_4028277]
    ON [dbo].[T_TANULOHAZIFELADAT]([C_HAZIFELADATID] ASC);


GO
PRINT N'Creating [dbo].[T_TANULOHAZIFELADAT].[I_T_4028282_4028280]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028282_4028280]
    ON [dbo].[T_TANULOHAZIFELADAT]([C_ROGZITOID] ASC);


GO
PRINT N'Creating [dbo].[T_TANULOHAZIFELADAT].[I_T_402827102_402827100]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402827102_402827100]
    ON [dbo].[T_TANULOHAZIFELADAT]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_TANULOHAZIFELADAT].[I_T_402827105_402827103]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402827105_402827103]
    ON [dbo].[T_TANULOHAZIFELADAT]([C_TANEVID] ASC);


GO
PRINT N'Creating unnamed constraint on [dbo].[T_TANULOHAZIFELADAT]...';


GO
ALTER TABLE [dbo].[T_TANULOHAZIFELADAT]
    ADD DEFAULT (getdate()) FOR [CREATED];


GO
PRINT N'Creating unnamed constraint on [dbo].[T_TANULOHAZIFELADAT]...';


GO
ALTER TABLE [dbo].[T_TANULOHAZIFELADAT]
    ADD DEFAULT (getdate()) FOR [LASTCHANGED];


GO
PRINT N'Creating unnamed constraint on [dbo].[T_TANULOHAZIFELADAT]...';


GO
ALTER TABLE [dbo].[T_TANULOHAZIFELADAT]
    ADD DEFAULT ('F') FOR [TOROLT];


GO
PRINT N'Creating unnamed constraint on [dbo].[T_TANULOHAZIFELADAT]...';


GO
ALTER TABLE [dbo].[T_TANULOHAZIFELADAT]
    ADD DEFAULT ((0)) FOR [SERIAL];


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


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


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH NOCHECK
    ADD CONSTRAINT [FK_4028123_4028121] FOREIGN KEY ([C_ROGZITOID]) REFERENCES [dbo].[T_FELHASZNALO] ([ID]);


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH NOCHECK
    ADD CONSTRAINT [FK_4028276_4028274] FOREIGN KEY ([C_HELYETTESITOID]) REFERENCES [dbo].[T_FELHASZNALO] ([ID]);


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


GO
ALTER TABLE [dbo].[T_TANULOHAZIFELADAT] WITH NOCHECK
    ADD CONSTRAINT [FK_4028279_4028277] FOREIGN KEY ([C_HAZIFELADATID]) REFERENCES [dbo].[T_HAZIFELADATOK] ([ID]);


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


GO
ALTER TABLE [dbo].[T_TANULOHAZIFELADAT] WITH NOCHECK
    ADD CONSTRAINT [FK_4028282_4028280] FOREIGN KEY ([C_ROGZITOID]) REFERENCES [dbo].[T_FELHASZNALO] ([ID]);


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


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


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


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

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


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



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

GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH CHECK CHECK CONSTRAINT [FK_4028120_4028118];

ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH CHECK CHECK CONSTRAINT [FK_4028123_4028121];

ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH CHECK CHECK CONSTRAINT [FK_4028126_4028124];

ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH CHECK CHECK CONSTRAINT [FK_4028129_4028127];

ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH CHECK CHECK CONSTRAINT [FK_402811202_402811200];

ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH CHECK CHECK CONSTRAINT [FK_402811205_402811203];

ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH CHECK CHECK CONSTRAINT [FK_4028276_4028274];

ALTER TABLE [dbo].[T_TANULOHAZIFELADAT] WITH CHECK CHECK CONSTRAINT [FK_4028279_4028277];

ALTER TABLE [dbo].[T_TANULOHAZIFELADAT] WITH CHECK CHECK CONSTRAINT [FK_4028282_4028280];

ALTER TABLE [dbo].[T_TANULOHAZIFELADAT] WITH CHECK CHECK CONSTRAINT [FK_402827102_402827100];

ALTER TABLE [dbo].[T_TANULOHAZIFELADAT] WITH CHECK CHECK CONSTRAINT [FK_402827105_402827103];


GO
PRINT N'Update complete.';


GO
