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


GO
CREATE TABLE [dbo].[T_LICENCE] (
    [ID]                  INT      IDENTITY (1, 1) NOT NULL,
    [C_DATE]              DATETIME NULL,
    [C_FULL]              CHAR (1) NOT NULL,
    [C_FUNCTION]          INT      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_4028200] PRIMARY KEY CLUSTERED ([ID] ASC)
);


GO
PRINT N'Creating [dbo].[T_LICENCE].[I_T_4028200_4028203]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028200_4028203]
    ON [dbo].[T_LICENCE]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_FUNCTION] ASC);


GO
PRINT N'Creating [dbo].[T_LICENCE].[I_T_402820002_402820000]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402820002_402820000]
    ON [dbo].[T_LICENCE]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_LICENCE].[I_T_402820005_402820003]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402820005_402820003]
    ON [dbo].[T_LICENCE]([C_TANEVID] ASC);


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


GO
CREATE TABLE [dbo].[T_LICENCEFUNKCIOKTIPUS] (
    [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_4028204] PRIMARY KEY CLUSTERED ([ID] ASC, [C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC)
);


GO
PRINT N'Creating [dbo].[T_LICENCEFUNKCIOKTIPUS].[I_T_402820402_402820400]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402820402_402820400]
    ON [dbo].[T_LICENCEFUNKCIOKTIPUS]([C_ALINTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_LICENCEFUNKCIOKTIPUS].[I_T_402820405_402820403]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402820405_402820403]
    ON [dbo].[T_LICENCEFUNKCIOKTIPUS]([C_ALTANEVID] ASC);


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_LICENCE]
    ADD DEFAULT ('T') FOR [C_FULL];


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


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


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


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


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_LICENCE] WITH NOCHECK
    ADD CONSTRAINT [FK_4028200_4028203] FOREIGN KEY ([C_FUNCTION], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_LICENCEFUNKCIOKTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_LICENCE] WITH CHECK CHECK CONSTRAINT [FK_402820002_402820000];

ALTER TABLE [dbo].[T_LICENCE] WITH CHECK CHECK CONSTRAINT [FK_402820005_402820003];

ALTER TABLE [dbo].[T_LICENCE] WITH CHECK CHECK CONSTRAINT [FK_4028200_4028203];

ALTER TABLE [dbo].[T_LICENCEFUNKCIOKTIPUS] WITH CHECK CHECK CONSTRAINT [FK_T_21038_4028205];

ALTER TABLE [dbo].[T_LICENCEFUNKCIOKTIPUS] WITH CHECK CHECK CONSTRAINT [FK_402820402_402820400];

ALTER TABLE [dbo].[T_LICENCEFUNKCIOKTIPUS] WITH CHECK CHECK CONSTRAINT [FK_402820405_402820403];


GO
PRINT N'Update complete.';


GO
