﻿PRINT N'Altering [dbo].[T_LEPELOADASJEGYZEK]...';


GO
ALTER TABLE [dbo].[T_LEPELOADASJEGYZEK]
    ADD [C_GONDVISELOALTALENGEDELYEZVE] CHAR (1) NULL,
        [C_GONDVISELOID]                INT      NULL;


GO
PRINT N'Creating [dbo].[T_LEPELOADASJEGYZEK].[I_T_4029120_4029118]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4029120_4029118]
    ON [dbo].[T_LEPELOADASJEGYZEK]([C_GONDVISELOID] ASC);


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


GO
ALTER TABLE [dbo].[T_LEPELOADASJEGYZEK] WITH NOCHECK
    ADD CONSTRAINT [FK_4029120_4029118] FOREIGN KEY ([C_GONDVISELOID]) REFERENCES [dbo].[T_GONDVISELO] ([ID]);


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


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


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


GO
ALTER TABLE [dbo].[T_LEPELOADASJEGYZEK] WITH CHECK CHECK CONSTRAINT [FK_4029120_4029118];


GO
PRINT N'Update complete.';


GO
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_LEPELOADASJEGYZEK', 'T_LEPELOADASJEGYZEK_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