﻿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_VEGZETTSEG]...';


GO
CREATE TABLE [dbo].[T_VEGZETTSEG] (
    [ID]                  INT            IDENTITY (1, 1) NOT NULL,
    [C_EGYEB]             NVARCHAR (255) NULL,
    [C_KEPESITESTIPUSID]  INT            NULL,
    [C_VEGZETTSEGTIPUSID] INT            NULL,
    [C_TANARID]           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_4028287] PRIMARY KEY CLUSTERED ([ID] ASC)
);


GO
PRINT N'Creating [dbo].[T_VEGZETTSEG].[I_T_4028287_4028289]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028287_4028289]
    ON [dbo].[T_VEGZETTSEG]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_KEPESITESTIPUSID] ASC);


GO
PRINT N'Creating [dbo].[T_VEGZETTSEG].[I_T_4028287_4028290]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028287_4028290]
    ON [dbo].[T_VEGZETTSEG]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_VEGZETTSEGTIPUSID] ASC);


GO
PRINT N'Creating [dbo].[T_VEGZETTSEG].[I_T_4028293_4028291]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028293_4028291]
    ON [dbo].[T_VEGZETTSEG]([C_TANARID] ASC);


GO
PRINT N'Creating [dbo].[T_VEGZETTSEG].[I_T_402828702_402828700]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402828702_402828700]
    ON [dbo].[T_VEGZETTSEG]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_VEGZETTSEG].[I_T_402828705_402828703]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402828705_402828703]
    ON [dbo].[T_VEGZETTSEG]([C_TANEVID] ASC);


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_VEGZETTSEG] WITH NOCHECK
    ADD CONSTRAINT [FK_4028287_4028289] FOREIGN KEY ([C_KEPESITESTIPUSID], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_TARGYKATEGORIATIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_VEGZETTSEG] WITH NOCHECK
    ADD CONSTRAINT [FK_4028287_4028290] FOREIGN KEY ([C_VEGZETTSEGTIPUSID], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_VEGZETTSEGTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_VEGZETTSEG] WITH NOCHECK
    ADD CONSTRAINT [FK_4028293_4028291] FOREIGN KEY ([C_TANARID]) REFERENCES [dbo].[T_FELHASZNALO] ([ID]);


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_VEGZETTSEG] WITH CHECK CHECK CONSTRAINT [FK_4028287_4028289];

ALTER TABLE [dbo].[T_VEGZETTSEG] WITH CHECK CHECK CONSTRAINT [FK_4028287_4028290];

ALTER TABLE [dbo].[T_VEGZETTSEG] WITH CHECK CHECK CONSTRAINT [FK_4028293_4028291];

ALTER TABLE [dbo].[T_VEGZETTSEG] WITH CHECK CHECK CONSTRAINT [FK_402828702_402828700];

ALTER TABLE [dbo].[T_VEGZETTSEG] WITH CHECK CHECK CONSTRAINT [FK_402828705_402828703];


GO
PRINT N'Update complete.';


GO
