﻿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].[T_CSATOLMANY_HAZIFELADATOK].[ELOZOTANEVIREKORDID].[MS_Description]...';


GO
EXECUTE sp_dropextendedproperty @name = N'MS_Description', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_CSATOLMANY_HAZIFELADATOK', @level2type = N'COLUMN', @level2name = N'ELOZOTANEVIREKORDID';


GO
PRINT N'Dropping [dbo].[T_CSATOLMANY_HAZIFELADATOK].[NNID].[MS_Description]...';


GO
EXECUTE sp_dropextendedproperty @name = N'MS_Description', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_CSATOLMANY_HAZIFELADATOK', @level2type = N'COLUMN', @level2name = N'NNID';


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


GO
ALTER TABLE [dbo].[T_CSATOLMANY_HAZIFELADATOK] DROP CONSTRAINT [FK_Csatolmany_HaziFeladatok_CsatolmanyId_REF_Csatolmany];


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


GO
ALTER TABLE [dbo].[T_CSATOLMANY_HAZIFELADATOK] DROP CONSTRAINT [FK_Csatolmany_HaziFeladatok_HaziFeladatokId_REF_HaziFeladatok];


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


GO
DROP TABLE [dbo].[T_CSATOLMANY_HAZIFELADATOK];


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


GO
CREATE TABLE [dbo].[T_HAZIFELADATCSATOLMANY] (
    [ID]                  INT      IDENTITY (1, 1) NOT NULL,
    [C_HAZIFELADATOKID]   INT      NOT NULL,
    [C_CSATOLMANYID]      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_HaziFeladatCsatolmany] PRIMARY KEY CLUSTERED ([ID] ASC)
);


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATCSATOLMANY] WITH NOCHECK
    ADD CONSTRAINT [FK_HaziFeladatCsatolmany_HaziFeladatokId_REF_HaziFeladatok] FOREIGN KEY ([C_HAZIFELADATOKID]) REFERENCES [dbo].[T_HAZIFELADATOK] ([ID]);


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATCSATOLMANY] WITH NOCHECK
    ADD CONSTRAINT [FK_HaziFeladatCsatolmany_CsatolmanyId_REF_Csatolmany] FOREIGN KEY ([C_CSATOLMANYID]) REFERENCES [dbo].[T_CSATOLMANY] ([ID]);


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


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


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


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


    GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[ID].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord egyedi azonosítója, generált IDENTITY(1, 1) (kivéve altáblák esetén, ahol a főtábla ID-ját kapja)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'ID';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[C_INTEZMENYID].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'Az intézmény ID-ja, amihez a rekord tartozik', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'C_INTEZMENYID';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[C_TANEVID].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A tanév ID-ja, amihez a rekord tartozik', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'C_TANEVID';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[TOROLT].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord logikai töröltségét jelző flag', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'TOROLT';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[SERIAL].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'Minden C# kódból történő módosítás esetén eggyel nő az értéke. Hogy párhuzamos módosítás esetnán ne íródjanak felül az adatok', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'SERIAL';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[LASTCHANGED].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'	A rekord utolsó módosításának időpontja', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'LASTCHANGED';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[CREATED].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord létrehozásának időpontja ', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'CREATED';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[MODIFIER].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekordot utoljára módosító felhasználó ID-ja', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'MODIFIER';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[CREATOR].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekordot létrehozó felhasználó ID-ja', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'CREATOR';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[ELOZOTANEVIREKORDID].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord előző tanévben lévő ID-ja', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'ELOZOTANEVIREKORDID';


GO
PRINT N'Creating [dbo].[T_HAZIFELADATCSATOLMANY].[NNID].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord régi, Neptun Naplóban lévő ID-ja. (migrációval került be)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_HAZIFELADATCSATOLMANY', @level2type = N'COLUMN', @level2name = N'NNID';


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATCSATOLMANY] WITH CHECK CHECK CONSTRAINT [FK_HaziFeladatCsatolmany_HaziFeladatokId_REF_HaziFeladatok];

ALTER TABLE [dbo].[T_HAZIFELADATCSATOLMANY] WITH CHECK CHECK CONSTRAINT [FK_HaziFeladatCsatolmany_CsatolmanyId_REF_Csatolmany];

ALTER TABLE [dbo].[T_HAZIFELADATCSATOLMANY] WITH CHECK CHECK CONSTRAINT [FK_HaziFeladatCsatolmany_IntezmenyId_REF_Intezmeny];

ALTER TABLE [dbo].[T_HAZIFELADATCSATOLMANY] WITH CHECK CHECK CONSTRAINT [FK_HaziFeladatCsatolmany_TanevId_REF_Tanev];



GO
EXEC dev.uspCreateSchemaViews 'T_HAZIFELADATCSATOLMANY'


GO
EXEC dev.sp_Global_GenerateAsyncAuditTriggerAll


GO

ALTER QUEUE auditLog.[AuditQueue]
WITH ACTIVATION (
  STATUS = ON,
  PROCEDURE_NAME = auditLog.usp_AuditProcessing,
  MAX_QUEUE_READERS = 10,
  EXECUTE AS 'Kreta_tech_user'
);


GO
