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

SET NUMERIC_ROUNDABORT OFF;


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


GO
CREATE TABLE [dbo].[T_MUVESZETIAG] (
    [ID]                   INT      NOT NULL,
    [C_ALINTEZMENYID]      INT      NOT NULL,
    [C_ALTANEVID]          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,
    [ELOZOTANEVIREKORDIDA] INT      NULL,
    [NNID]                 INT      NULL,
    CONSTRAINT [PK_T_4028803] PRIMARY KEY CLUSTERED ([ID] ASC, [C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC)
);


GO
PRINT N'Creating [dbo].[T_MUVESZETIAG].[I_T_402880302_402880300]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402880302_402880300]
    ON [dbo].[T_MUVESZETIAG]([C_ALINTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_MUVESZETIAG].[I_T_402880305_402880303]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402880305_402880303]
    ON [dbo].[T_MUVESZETIAG]([C_ALTANEVID] ASC);


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


GO
CREATE TABLE [dbo].[T_ZENEMUVESZETIAGTIPUS] (
    [ID]                   INT      NOT NULL,
    [C_ALINTEZMENYID]      INT      NOT NULL,
    [C_ALTANEVID]          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,
    [ELOZOTANEVIREKORDIDA] INT      NULL,
    [NNID]                 INT      NULL,
    CONSTRAINT [PK_T_4028802] PRIMARY KEY CLUSTERED ([ID] ASC, [C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC)
);


GO
PRINT N'Creating [dbo].[T_ZENEMUVESZETIAGTIPUS].[I_T_402880202_402880200]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402880202_402880200]
    ON [dbo].[T_ZENEMUVESZETIAGTIPUS]([C_ALINTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_ZENEMUVESZETIAGTIPUS].[I_T_402880205_402880203]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402880205_402880203]
    ON [dbo].[T_ZENEMUVESZETIAGTIPUS]([C_ALTANEVID] ASC);


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_MUVESZETIAG] WITH NOCHECK
    ADD CONSTRAINT [FK_T_21038_4028804] FOREIGN KEY ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_DICTIONARYITEMBASE] ([ID], [C_INTEZMENYID], [C_TANEVID]);


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


GO
ALTER TABLE [dbo].[T_MUVESZETIAG] WITH NOCHECK
    ADD CONSTRAINT [FK_402880302_402880300] FOREIGN KEY ([C_ALINTEZMENYID]) REFERENCES [dbo].[T_INTEZMENY] ([ID]);


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


GO
ALTER TABLE [dbo].[T_MUVESZETIAG] WITH NOCHECK
    ADD CONSTRAINT [FK_402880305_402880303] FOREIGN KEY ([C_ALTANEVID]) REFERENCES [dbo].[T_TANEV] ([ID]);


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


GO
ALTER TABLE [dbo].[T_ZENEMUVESZETIAGTIPUS] WITH NOCHECK
    ADD CONSTRAINT [FK_T_21038_4028805] FOREIGN KEY ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_DICTIONARYITEMBASE] ([ID], [C_INTEZMENYID], [C_TANEVID]);


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


GO
ALTER TABLE [dbo].[T_ZENEMUVESZETIAGTIPUS] WITH NOCHECK
    ADD CONSTRAINT [FK_402880202_402880200] FOREIGN KEY ([C_ALINTEZMENYID]) REFERENCES [dbo].[T_INTEZMENY] ([ID]);


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


GO
ALTER TABLE [dbo].[T_ZENEMUVESZETIAGTIPUS] WITH NOCHECK
    ADD CONSTRAINT [FK_402880205_402880203] FOREIGN KEY ([C_ALTANEVID]) REFERENCES [dbo].[T_TANEV] ([ID]);


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


GO
CREATE VIEW [dbo].T_MUVESZETIAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUVESZETIAG
GO
PRINT N'Creating [dbo].[T_ZENEMUVESZETIAGTIPUS_OSSZES]...';


GO
CREATE VIEW [dbo].T_ZENEMUVESZETIAGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ZENEMUVESZETIAGTIPUS
GO
PRINT N'Checking existing data against newly created constraints';


GO
ALTER TABLE [dbo].[T_MUVESZETIAG] WITH CHECK CHECK CONSTRAINT [FK_T_21038_4028804];

ALTER TABLE [dbo].[T_MUVESZETIAG] WITH CHECK CHECK CONSTRAINT [FK_402880302_402880300];

ALTER TABLE [dbo].[T_MUVESZETIAG] WITH CHECK CHECK CONSTRAINT [FK_402880305_402880303];

ALTER TABLE [dbo].[T_ZENEMUVESZETIAGTIPUS] WITH CHECK CHECK CONSTRAINT [FK_T_21038_4028805];

ALTER TABLE [dbo].[T_ZENEMUVESZETIAGTIPUS] WITH CHECK CHECK CONSTRAINT [FK_402880202_402880200];

ALTER TABLE [dbo].[T_ZENEMUVESZETIAGTIPUS] WITH CHECK CHECK CONSTRAINT [FK_402880205_402880203];


GO
PRINT N'Update complete.';


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