﻿GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;

SET NUMERIC_ROUNDABORT OFF;




GO
PRINT N'Dropping [dbo].[FK_OraFile_FileId_REF_File]...';


GO
ALTER TABLE [dbo].[T_ORAFILE] DROP CONSTRAINT [FK_OraFile_FileId_REF_File];


GO
PRINT N'Altering [dbo].[T_KIRSZIRFELADATELLATASIHELY]...';


GO
ALTER TABLE [dbo].[T_KIRSZIRFELADATELLATASIHELY] DROP COLUMN [C_ENGEDELYEZETTOSZTALY], COLUMN [C_ENGEDELYZETTOSZTALYLETSZAM], COLUMN [C_FELADATELLATASIHELYKOD];


GO
PRINT N'Altering [dbo].[T_ORAFILE]...';


GO
ALTER TABLE [dbo].[T_ORAFILE] DROP COLUMN [C_FILEID];


GO
ALTER TABLE [dbo].[T_ORAFILE]
    ADD [C_ORAIDOPONT]       DATETIME        NULL,
        [C_ORASZAM]          INT             NULL,
        [C_MEGJEGYZES]       NVARCHAR (1000) NULL,
        [C_TANTARGYID]       INT             NOT NULL,
        [C_DKT_FILEID]       INT             NOT NULL,
        [C_ALKALMAZOTTID]    INT             NOT NULL,
        [C_OSZTALYCSOPORTID] INT             NOT NULL;


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


GO
ALTER TABLE [dbo].[T_ORAFILE] WITH NOCHECK
    ADD CONSTRAINT [FK_OraFile_AlkalmazottId_REF_Alkalmazott] FOREIGN KEY ([C_ALKALMAZOTTID]) REFERENCES [dbo].[T_ALKALMAZOTT] ([ID]);


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


GO
ALTER TABLE [dbo].[T_ORAFILE] WITH NOCHECK
    ADD CONSTRAINT [FK_OraFile_DKT_FileId_REF_DKT_File] FOREIGN KEY ([C_DKT_FILEID]) REFERENCES [dbo].[T_DKT_FILE] ([ID]);


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


GO
ALTER TABLE [dbo].[T_ORAFILE] WITH NOCHECK
    ADD CONSTRAINT [FK_OraFile_OsztalyCsoportId_REF_OsztalyCsoport] FOREIGN KEY ([C_OSZTALYCSOPORTID]) REFERENCES [dbo].[T_OSZTALYCSOPORT] ([ID]);


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


GO
ALTER TABLE [dbo].[T_ORAFILE] WITH NOCHECK
    ADD CONSTRAINT [FK_OraFile_TantargyId_REF_Tantargy] FOREIGN KEY ([C_TANTARGYID]) REFERENCES [dbo].[T_TANTARGY] ([ID]);





GO
ALTER TABLE [dbo].[T_ORAFILE] WITH CHECK CHECK CONSTRAINT [FK_OraFile_AlkalmazottId_REF_Alkalmazott];

ALTER TABLE [dbo].[T_ORAFILE] WITH CHECK CHECK CONSTRAINT [FK_OraFile_DKT_FileId_REF_DKT_File];

ALTER TABLE [dbo].[T_ORAFILE] WITH CHECK CHECK CONSTRAINT [FK_OraFile_OsztalyCsoportId_REF_OsztalyCsoport];

ALTER TABLE [dbo].[T_ORAFILE] WITH CHECK CHECK CONSTRAINT [FK_OraFile_TantargyId_REF_Tantargy];


GO
PRINT N'Update complete.';


GO
EXEC dev.uspCreateSchemaViews 'T_ORAFILE, T_KIRSZIRFELADATELLATASIHELY';
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