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

SET NUMERIC_ROUNDABORT OFF;


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


GO
ALTER TABLE [dbo].[T_INTEZMENYADATOK]
    ADD [C_ALAPKRETA]               CHAR (1) DEFAULT ('F') NOT NULL,
        [C_KRETAESL]                CHAR (1) DEFAULT ('F') NOT NULL,
        [C_KRETAEUGYINTEZES]        CHAR (1) DEFAULT ('F') NOT NULL,
        [C_SNINEVELESIFORMATIPUSID] INT NULL;

GO
UPDATE [dbo].[T_INTEZMENYADATOK]
	SET [C_SNINEVELESIFORMATIPUSID] = 7723;

GO
ALTER TABLE [dbo].[T_INTEZMENYADATOK]
    ALTER COLUMN [C_SNINEVELESIFORMATIPUSID] INT NOT NULL;

GO
PRINT N'Creating [dbo].[T_INTEZMENYADATOK].[I_T_4025209_4029036]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025209_4029036]
    ON [dbo].[T_INTEZMENYADATOK]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_SNINEVELESIFORMATIPUSID] ASC);


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


GO
ALTER TABLE [dbo].[T_INTEZMENYADATOK] WITH NOCHECK
    ADD CONSTRAINT [FK_4025209_4029036] FOREIGN KEY ([C_SNINEVELESIFORMATIPUSID], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_SNITANULONEVELESIFORMATIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


GO
PRINT N'Refreshing [dbo].[T_INTEZMENYADATOK_OSSZES]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[T_INTEZMENYADATOK_OSSZES]';


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


GO
ALTER TABLE [dbo].[T_INTEZMENYADATOK] WITH CHECK CHECK CONSTRAINT [FK_4025209_4029036];


GO
PRINT N'Update complete.';


GO


--------------------


PRINT '--- intézményi view-k (dbo táblákkal megegyezõ nevû és a tábla_OSSZES nevûek) frissítése ---'

DECLARE  @viewname nvarchar(100), @pureview nvarchar(100)

DECLARE semaviewk CURSOR LOCAL FOR 
  SELECT '['+TABLE_SCHEMA + '].[' + TABLE_NAME + ']', TABLE_NAME
  FROM INFORMATION_SCHEMA.TABLES
  WHERE TABLE_TYPE = 'VIEW' and TABLE_SCHEMA LIKE 'KR[_]%[_]Schema'
  AND TABLE_NAME in ('T_INTEZMENYADATOK', 'T_INTEZMENYADATOK_OSSZES') -- ha csak néhány VIEW frissült, akkor a gyorsabb futásért ide fel lehet sorolni
  ORDER BY TABLE_SCHEMA, TABLE_NAME

OPEN semaviewk
FETCH NEXT FROM semaviewk INTO @viewname, @pureview

WHILE @@FETCH_STATUS = 0 BEGIN
    PRINT @viewname
    EXEC sp_refreshview @viewname

    FETCH NEXT FROM semaviewk INTO @viewname, @pureview
END             

CLOSE semaviewk
DEALLOCATE semaviewk
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
