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


GO
CREATE TABLE [dbo].[T_TEREMELERHETOSEG] (
    [ID]                  INT      IDENTITY (1, 1) NOT NULL,
    [C_HETNAPJA]          INT      NOT NULL,
    [C_KEZDETE]           DATETIME NOT NULL,
    [C_VEGE]              DATETIME NOT NULL,
    [C_TEREMID]           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_4028735] PRIMARY KEY CLUSTERED ([ID] ASC)
);


GO
PRINT N'Creating [dbo].[T_TEREMELERHETOSEG].[I_T_4028735_4028736]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028735_4028736]
    ON [dbo].[T_TEREMELERHETOSEG]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_HETNAPJA] ASC);


GO
PRINT N'Creating [dbo].[T_TEREMELERHETOSEG].[I_T_4028741_4028739]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028741_4028739]
    ON [dbo].[T_TEREMELERHETOSEG]([C_TEREMID] ASC);


GO
PRINT N'Creating [dbo].[T_TEREMELERHETOSEG].[I_T_402873502_402873500]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402873502_402873500]
    ON [dbo].[T_TEREMELERHETOSEG]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_TEREMELERHETOSEG].[I_T_402873505_402873503]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402873505_402873503]
    ON [dbo].[T_TEREMELERHETOSEG]([C_TANEVID] ASC);


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_TEREMELERHETOSEG] WITH NOCHECK
    ADD CONSTRAINT [FK_4028735_4028736] FOREIGN KEY ([C_HETNAPJA], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_NAPTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_TEREMELERHETOSEG] WITH NOCHECK
    ADD CONSTRAINT [FK_4028741_4028739] FOREIGN KEY ([C_TEREMID]) REFERENCES [dbo].[T_TEREM] ([ID]);


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_TEREMELERHETOSEG] WITH CHECK CHECK CONSTRAINT [FK_4028735_4028736];

ALTER TABLE [dbo].[T_TEREMELERHETOSEG] WITH CHECK CHECK CONSTRAINT [FK_4028741_4028739];

ALTER TABLE [dbo].[T_TEREMELERHETOSEG] WITH CHECK CHECK CONSTRAINT [FK_402873502_402873500];

ALTER TABLE [dbo].[T_TEREMELERHETOSEG] WITH CHECK CHECK CONSTRAINT [FK_402873505_402873503];


GO
PRINT N'Update complete.';


GO
