﻿--ÖSSZES FH TÖRLÉSE
DECLARE @sql NVARCHAR(MAX)=''

SELECT  @sql = @sql + 'ALTER TABLE T_EGYHAZTARTASBANELOK DROP CONSTRAINT [' + RTRIM(fk.name) +'];' + CHAR(13) + CHAR(10)
FROM sys.foreign_keys fk
WHERE fk.parent_object_id = OBJECT_ID('T_EGYHAZTARTASBANELOK')

EXEC sp_executesql @sql
GO

DROP TABLE IF EXISTS T_EGYHAZTARTASBANELOK
GO

CREATE TABLE  [dbo].T_EGYHAZTARTASBANELOK (
    ID                                int                              NOT NULL IDENTITY(1,1),
    C_ANYJANEVE                       nvarchar(255)                    NOT NULL,
    C_EMAIL                           nvarchar(255)                    NULL,
    C_ISCOVIDFERTOZOTT                char(1)                          DEFAULT 'F' NOT NULL,
    C_ISFELHASZNALOTOROLT             char(1)                          DEFAULT 'F' NOT NULL,
    C_ISGONDVISELOTOROLT              char(1)                          DEFAULT 'F' NOT NULL,
    C_NEV                             nvarchar(255)                    NOT NULL,
    C_ROKONSAGIFOKID                  int                              NOT NULL,
    C_SZULETESIHELY                   nvarchar(255)                    NOT NULL,
    C_SZULETESIIDO                    datetime                         NOT NULL,
    C_TAJSZAM                         nvarchar(255)                    NOT NULL,
    C_TELEFON                         nvarchar(255)                    NULL,
    C_ROGZITOGONDVISELOID             int                              NULL,
    C_ROGZITOFELHASZNALOID            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,
    ELOZOTANEVIREKORDID               int                              NULL,
    CONSTRAINT PK_EgyHaztartasbanElok PRIMARY KEY (ID)  
)
GO

ALTER TABLE [DBO].T_EGYHAZTARTASBANELOK 
  ADD CONSTRAINT FK_EgyHaztartasbanElok_RokonsagiFokId_IntezmenyId_TanevId_REF_RokonsagiFok 
  FOREIGN KEY (C_ROKONSAGIFOKID, C_INTEZMENYID, C_TANEVID) 
  REFERENCES [dbo].T_ROKONSAGIFOK (ID, C_ALINTEZMENYID, C_ALTANEVID)
GO

ALTER TABLE [DBO].T_EGYHAZTARTASBANELOK 
  ADD CONSTRAINT FK_EgyHaztartasbanElok_RogzitoGondviseloId_REF_Gondviselo 
  FOREIGN KEY (C_ROGZITOGONDVISELOID) 
  REFERENCES [DBO].T_GONDVISELO (ID)
GO

ALTER TABLE [DBO].T_EGYHAZTARTASBANELOK 
  ADD CONSTRAINT FK_EgyHaztartasbanElok_RogzitoFelhasznaloId_REF_Felhasznalo 
  FOREIGN KEY (C_ROGZITOFELHASZNALOID) 
  REFERENCES [DBO].T_FELHASZNALO (ID)
GO

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

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

EXEC dev.uspCreateSchemaViews 'T_EGYHAZTARTASBANELOK'
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

