﻿--Migration
CREATE TABLE  [dbo].T_JUTTATAS (
    ID                                int                              NOT NULL IDENTITY(1,1),
    C_ELUTASITASOKA                   int                              NULL,
    C_ISAKTIV                         char(1)                          DEFAULT 'F' NOT NULL,
    C_ISJOGOSULT                      char(1)                          DEFAULT 'F' NOT NULL,
    C_JUTTATASTIPUSID                 int                              NULL,
    C_OSSZEG                          int                              NULL,
    C_TANULOID                        int                              NOT NULL,
    C_INTEZMENYID                     int                              NOT NULL,
    C_TANEVID                         int                              NOT NULL,
    TOROLT                            char(1)                          NOT NULL DEFAULT 'F',
    SERIAL                            int                              DEFAULT 0 NOT NULL,
    LASTCHANGED                       datetime                         DEFAULT GETDATE() NOT NULL,
    CREATED                           datetime                         DEFAULT GETDATE() NOT NULL,
    MODIFIER                          int                              NULL,
    CREATOR                           int                              NULL,
    CONSTRAINT PK_Juttatas PRIMARY KEY (ID)  
)
GO

/*============================================================================*/
/* Table : T_JUTTATASTIPUS                                                        */
/*============================================================================*/
/* Package: Kreta */
CREATE TABLE  [dbo].T_JUTTATASTIPUS (
    ID                                int                              NOT NULL,
    C_ALINTEZMENYID                   int                              NOT NULL,
    C_ALTANEVID                       int                              NOT NULL,
    TOROLT                            char(1)                          NOT NULL DEFAULT 'F',
    SERIAL                            int                              DEFAULT 0 NOT NULL,
    LASTCHANGED                       datetime                         DEFAULT GETDATE() NOT NULL,
    CREATED                           datetime                         DEFAULT GETDATE() NOT NULL,
    MODIFIER                          int                              NULL,
    CREATOR                           int                              NULL,
    CONSTRAINT PK_JuttatasTipus PRIMARY KEY (ID, C_ALINTEZMENYID, C_ALTANEVID) 
)
GO

CREATE INDEX NCI_Juttatas_IntezmenyId_TanevId_JuttatasTipusId ON T_JUTTATAS (C_INTEZMENYID, C_TANEVID, C_JUTTATASTIPUSID)
GO
CREATE INDEX NCI_Juttatas_TanuloId ON T_JUTTATAS (C_TANULOID)
GO
CREATE INDEX NCI_Juttatas_IntezmenyId ON T_JUTTATAS (C_INTEZMENYID)
GO
CREATE INDEX NCI_Juttatas_TanevId ON T_JUTTATAS (C_TANEVID)
GO
CREATE INDEX NCI_JuttatasTipus_AlIntezmenyId ON T_JUTTATASTIPUS (C_ALINTEZMENYID)
GO
CREATE INDEX NCI_JuttatasTipus_AlTanevId ON T_JUTTATASTIPUS (C_ALTANEVID)
GO

ALTER TABLE [DBO].T_JUTTATAS 
  ADD CONSTRAINT FK_Juttatas_JuttatasTipusId_IntezmenyId_TanevId_REF_JuttatasTipus 
  FOREIGN KEY (C_JUTTATASTIPUSID, C_INTEZMENYID, C_TANEVID) 
  REFERENCES [dbo].T_JUTTATASTIPUS (ID, C_ALINTEZMENYID, C_ALTANEVID)

GO

ALTER TABLE [DBO].T_JUTTATAS 
  ADD CONSTRAINT FK_Juttatas_TanuloId_REF_Tanulo 
  FOREIGN KEY (C_TANULOID) 
  REFERENCES [DBO].T_TANULO (ID)
GO



ALTER TABLE [DBO].T_JUTTATAS 
  ADD CONSTRAINT FK_Juttatas_IntezmenyId_REF_Intezmeny 
  FOREIGN KEY (C_INTEZMENYID) 
  REFERENCES [DBO].T_INTEZMENY (ID)
GO



ALTER TABLE [DBO].T_JUTTATAS 
  ADD CONSTRAINT FK_Juttatas_TanevId_REF_Tanev 
  FOREIGN KEY (C_TANEVID) 
  REFERENCES [DBO].T_TANEV (ID)
GO

ALTER TABLE [DBO].T_JUTTATASTIPUS 
  ADD CONSTRAINT FK_JuttatasTipus_Id_AlintezmenyId_AltanevId_REF_DictionaryItemBase 
  FOREIGN KEY (ID, C_ALINTEZMENYID, C_ALTANEVID) 
  REFERENCES [DBO].T_DICTIONARYITEMBASE (ID, C_INTEZMENYID, C_TANEVID)


GO



ALTER TABLE [DBO].T_JUTTATASTIPUS 
  ADD CONSTRAINT FK_JuttatasTipus_AlIntezmenyId_REF_Intezmeny 
  FOREIGN KEY (C_ALINTEZMENYID) 
  REFERENCES [DBO].T_INTEZMENY (ID)
GO



ALTER TABLE [DBO].T_JUTTATASTIPUS 
  ADD CONSTRAINT FK_JuttatasTipus_AlTanevId_REF_Tanev 
  FOREIGN KEY (C_ALTANEVID) 
  REFERENCES [DBO].T_TANEV (ID)
GO


EXEC dev.uspCreateSchemaViews 'T_JUTTATASTIPUS, T_JUTTATAS'
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


