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


GO
CREATE TABLE [dbo].[T_MOBILDBINFO] (
    [ID]                  INT      IDENTITY (1, 1) NOT NULL,
    [C_VERSION]           INT      NOT NULL,
    [C_INTEZMENYID]       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_4028354] PRIMARY KEY CLUSTERED ([ID] ASC)
);


GO
PRINT N'Creating [dbo].[T_MOBILDBINFO].[I_T_4028358_4028356]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028358_4028356]
    ON [dbo].[T_MOBILDBINFO]([C_INTEZMENYID] ASC);


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


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


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_MOBILDBINFO] WITH CHECK CHECK CONSTRAINT [FK_4028358_4028356];


GO
PRINT N'Update complete.';


GO

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='UK_MOBILDBINFO_INTEZMENYID') BEGIN
	ALTER TABLE T_MOBILDBINFO
	ADD CONSTRAINT UK_MOBILDBINFO_INTEZMENYID UNIQUE (C_INTEZMENYID);
END
GO
