﻿
GO
PRINT N'Dropping Index [dbo].[T_TANULOESEMENY].[NCI_TanuloEsemeny_BairasTanuloId]...';


GO
DROP INDEX IF EXISTS [NCI_TanuloEsemeny_BairasTanuloId]
    ON [dbo].[T_TANULOESEMENY];


GO
PRINT N'Dropping Foreign Key [dbo].[FK_TanuloEsemeny_BairasTanuloId_REF_Tanulo]...';


GO
ALTER TABLE [dbo].[T_TANULOESEMENY] DROP CONSTRAINT IF EXISTS [FK_TanuloEsemeny_BairasTanuloId_REF_Tanulo];


GO
PRINT N'Altering Table [dbo].[T_HELYETTESITESIIDOSZAK]...';


GO
ALTER TABLE [dbo].[T_HELYETTESITESIIDOSZAK]
    ADD [C_ISTULORA] CHAR (1) DEFAULT ('F') NOT NULL;


GO
PRINT N'Altering Table [dbo].[T_MUNKAUGYIADATOK]...';


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK]
    ADD [C_ISVEZETOPEDAGOGUS] CHAR (1) DEFAULT ('F') NOT NULL;


GO
PRINT N'Altering Table [dbo].[T_TANULOESEMENY]...';


GO
ALTER TABLE [dbo].[T_TANULOESEMENY] DROP COLUMN IF EXISTS [C_BAIRASTANULOID];


GO
IF COL_LENGTH('dbo.T_TANULOESEMENY', 'C_BEIRASTANULOID') IS NULL BEGIN
  ALTER TABLE [dbo].[T_TANULOESEMENY]
    ADD [C_BEIRASTANULOID] INT NULL;
END

GO
PRINT N'Creating Index [dbo].[T_TANULOESEMENY].[NCI_TanuloEsemeny_BeirasTanuloId]...';


GO
IF NOT EXISTS (
    SELECT 1 
    FROM sys.indexes 
    WHERE name='NCI_TanuloEsemeny_BeirasTanuloId' AND object_id = OBJECT_ID('dbo.T_TANULOESEMENY') ) BEGIN

  CREATE NONCLUSTERED INDEX [NCI_TanuloEsemeny_BeirasTanuloId]
    ON [dbo].[T_TANULOESEMENY]([C_BEIRASTANULOID] ASC);
END

GO
PRINT N'Creating Foreign Key [dbo].[FK_TanuloEsemeny_BeirasTanuloId_REF_Tanulo]...';


GO
IF NOT EXISTS (SELECT * 
  FROM sys.foreign_keys 
  WHERE name = N'FK_TanuloEsemeny_BeirasTanuloId_REF_Tanulo'
  AND parent_object_id = OBJECT_ID(N'dbo.T_TANULOESEMENY')) BEGIN

  ALTER TABLE [dbo].[T_TANULOESEMENY] WITH NOCHECK
    ADD CONSTRAINT [FK_TanuloEsemeny_BeirasTanuloId_REF_Tanulo] FOREIGN KEY ([C_BEIRASTANULOID]) REFERENCES [dbo].[T_TANULO] ([ID]);
END

GO
ALTER TABLE [dbo].[T_TANULOESEMENY] WITH CHECK CHECK CONSTRAINT [FK_TanuloEsemeny_BeirasTanuloId_REF_Tanulo];


GO
PRINT N'Update complete.';


GO

EXEC dev.uspCreateSchemaViews 'T_HELYETTESITESIIDOSZAK, T_MUNKAUGYIADATOK, T_TANULOESEMENY'
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
