﻿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_4025942_4025941]...';


GO
ALTER TABLE [dbo].[T_TANULOESEMENY] DROP CONSTRAINT [FK_4025942_4025941];


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


GO
ALTER TABLE [dbo].[T_ERTEKELESMONDATBANK] DROP CONSTRAINT [FK_4027923_4027921];


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


GO
ALTER TABLE [dbo].[T_OSSZEFUGGOSZAKGYAK] DROP CONSTRAINT [FK_4028372_4028370];


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


GO
ALTER TABLE [dbo].[T_OGORARENDIORA] DROP CONSTRAINT [FK_4027854_4027852];


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


GO
ALTER TABLE [dbo].[T_FOGLALKOZAS] DROP CONSTRAINT [FK_4025428_4025426];


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


GO
ALTER TABLE [dbo].[T_ORATERVTARGY] DROP CONSTRAINT [FK_4026020_4026018];


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


GO
ALTER TABLE [dbo].[T_TANULOERTEKELES] DROP CONSTRAINT [FK_4025662_4025660];


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


GO
ALTER TABLE [dbo].[T_TANITASIORA] DROP CONSTRAINT [FK_4025608_4025607];


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


GO
ALTER TABLE [dbo].[T_HAZIFELADATOK] DROP CONSTRAINT [FK_4028120_4028118];


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


GO
ALTER TABLE [dbo].[T_TANTARGY] DROP CONSTRAINT [FK_4025408_4025407];


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


GO
ALTER TABLE [dbo].[T_TANTARGY] DROP CONSTRAINT [FK_402539902_402539900];


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


GO
ALTER TABLE [dbo].[T_TANTARGY] DROP CONSTRAINT [FK_402539905_402539903];


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


GO
ALTER TABLE [dbo].[T_TANTARGY] DROP CONSTRAINT [FK_4025399_4025404];


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


GO
ALTER TABLE [dbo].[T_OGFOGLALKOZAS] DROP CONSTRAINT [FK_4027782_4027781];


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


GO
ALTER TABLE [dbo].[T_OGTANTARGYFOGLALTSAG] DROP CONSTRAINT [FK_4027786_4027784];


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


GO
ALTER TABLE [dbo].[T_TANMENET] DROP CONSTRAINT [FK_4025597_4025595];


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


GO
ALTER TABLE [dbo].[T_TANARITANTARGY] DROP CONSTRAINT [FK_4025946_4025944];


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


GO
ALTER TABLE [dbo].[T_ORARENDIORA] DROP CONSTRAINT [FK_4026321_4026319];


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


GO
ALTER TABLE [dbo].[T_TANULOMENTESSEG] DROP CONSTRAINT [FK_4025776_4025775];


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


GO
ALTER TABLE [dbo].[T_OGTEREM_TANTARGY] DROP CONSTRAINT [FK_4027774_4027772];


GO
PRINT N'Starting rebuilding table [dbo].[T_TANTARGY]...';


GO
BEGIN TRANSACTION;

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

SET XACT_ABORT ON;

CREATE TABLE [dbo].[tmp_ms_xx_T_TANTARGY] (
    [ID]                             INT            IDENTITY (1, 1) NOT NULL,
    [C_GYAKORLATI]                   CHAR (1)       DEFAULT ('F') NULL,
    [C_NEV]                          NVARCHAR (255) NOT NULL,
    [C_ROVIDNEV]                     NVARCHAR (20)  NULL,
    [C_TARGYKATEGORIA]               INT            NOT NULL,
    [C_ALTANTARGYKENTNYOMTATVANYBAN] CHAR (1)       DEFAULT ('F') NULL,
    [C_NEVNYOMTATVANYBAN]            NVARCHAR (255) NULL,
    [C_TANORANKIVULI]                CHAR (1)       DEFAULT ('F') NULL,
    [C_IMPORTALT]                    CHAR (1)       DEFAULT ('F') NULL,
    [C_FOTARGYE]                     CHAR (1)       DEFAULT ('T') NULL,
    [C_ANGOLNEV]                     NVARCHAR (255) NULL,
    [C_NEMETNEV]                     NVARCHAR (255) NULL,
    [C_FOTARGYID]                    INT            NULL,
    [C_INTEZMENYID]                  INT            NOT NULL,
    [C_TANEVID]                      INT            NOT NULL,
    [TOROLT]                         CHAR (1)       DEFAULT ('F') NOT NULL,
    [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,
    [NNID]                           INT            NULL,
    CONSTRAINT [tmp_ms_xx_constraint_PK_T_40253991] PRIMARY KEY CLUSTERED ([ID] ASC)
);

IF EXISTS (SELECT TOP 1 1 
           FROM   [dbo].[T_TANTARGY])
    BEGIN
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_TANTARGY] ON;
        INSERT INTO [dbo].[tmp_ms_xx_T_TANTARGY] ([ID], [C_GYAKORLATI], [C_NEV], [C_ROVIDNEV], [C_TARGYKATEGORIA], [C_ALTANTARGYKENTNYOMTATVANYBAN], [C_NEVNYOMTATVANYBAN], [C_TANORANKIVULI], [C_IMPORTALT], [C_FOTARGYE], [C_FOTARGYID], [C_INTEZMENYID], [C_TANEVID], [TOROLT], [SERIAL], [LASTCHANGED], [CREATED], [MODIFIER], [CREATOR], [ELOZOTANEVIREKORDID], [NNID])
        SELECT   [ID],
                 [C_GYAKORLATI],
                 [C_NEV],
                 [C_ROVIDNEV],
                 [C_TARGYKATEGORIA],
                 [C_ALTANTARGYKENTNYOMTATVANYBAN],
                 [C_NEVNYOMTATVANYBAN],
                 [C_TANORANKIVULI],
                 [C_IMPORTALT],
                 [C_FOTARGYE],
                 [C_FOTARGYID],
                 [C_INTEZMENYID],
                 [C_TANEVID],
                 [TOROLT],
                 [SERIAL],
                 [LASTCHANGED],
                 [CREATED],
                 [MODIFIER],
                 [CREATOR],
                 [ELOZOTANEVIREKORDID],
                 [NNID]
        FROM     [dbo].[T_TANTARGY]
        ORDER BY [ID] ASC;
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_TANTARGY] OFF;
    END

DROP TABLE [dbo].[T_TANTARGY];

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_T_TANTARGY]', N'T_TANTARGY';

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_constraint_PK_T_40253991]', N'PK_T_4025399', N'OBJECT';

COMMIT TRANSACTION;

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;


GO
PRINT N'Creating [dbo].[T_TANTARGY].[I_T_4025399_4025404]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025399_4025404]
    ON [dbo].[T_TANTARGY]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_TARGYKATEGORIA] ASC);


GO
PRINT N'Creating [dbo].[T_TANTARGY].[I_T_4025408_4025407]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025408_4025407]
    ON [dbo].[T_TANTARGY]([C_FOTARGYID] ASC);


GO
PRINT N'Creating [dbo].[T_TANTARGY].[I_T_402539902_402539900]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402539902_402539900]
    ON [dbo].[T_TANTARGY]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_TANTARGY].[I_T_402539905_402539903]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402539905_402539903]
    ON [dbo].[T_TANTARGY]([C_TANEVID] ASC);


GO
PRINT N'Creating [dbo].[T_TANTARGY].[UK_4025402]...';


GO
CREATE UNIQUE NONCLUSTERED INDEX [UK_4025402]
    ON [dbo].[T_TANTARGY]([C_NEV] ASC, [C_INTEZMENYID] ASC, [C_TANEVID] ASC) WHERE ([TOROLT]='F');


GO
PRINT N'Creating [dbo].[T_TANTARGY].[IX_TANTARGY_INTEZMENYID_ID]...';


GO
CREATE NONCLUSTERED INDEX [IX_TANTARGY_INTEZMENYID_ID]
    ON [dbo].[T_TANTARGY]([C_INTEZMENYID] ASC, [ID] ASC)
    INCLUDE([C_NEV], [C_ROVIDNEV], [C_TARGYKATEGORIA], [C_TANEVID]);


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_TANTARGY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025408_4025407] FOREIGN KEY ([C_FOTARGYID]) REFERENCES [dbo].[T_TANTARGY] ([ID]);


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


GO
ALTER TABLE [dbo].[T_TANTARGY] WITH NOCHECK
    ADD CONSTRAINT [FK_402539902_402539900] FOREIGN KEY ([C_INTEZMENYID]) REFERENCES [dbo].[T_INTEZMENY] ([ID]);


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


GO
ALTER TABLE [dbo].[T_TANTARGY] WITH NOCHECK
    ADD CONSTRAINT [FK_402539905_402539903] FOREIGN KEY ([C_TANEVID]) REFERENCES [dbo].[T_TANEV] ([ID]);


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


GO
ALTER TABLE [dbo].[T_TANTARGY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025399_4025404] FOREIGN KEY ([C_TARGYKATEGORIA], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_TARGYKATEGORIATIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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

ALTER TABLE [dbo].[T_ERTEKELESMONDATBANK] WITH CHECK CHECK CONSTRAINT [FK_4027923_4027921];

ALTER TABLE [dbo].[T_OSSZEFUGGOSZAKGYAK] WITH CHECK CHECK CONSTRAINT [FK_4028372_4028370];

ALTER TABLE [dbo].[T_OGORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4027854_4027852];

ALTER TABLE [dbo].[T_FOGLALKOZAS] WITH CHECK CHECK CONSTRAINT [FK_4025428_4025426];

ALTER TABLE [dbo].[T_ORATERVTARGY] WITH CHECK CHECK CONSTRAINT [FK_4026020_4026018];

ALTER TABLE [dbo].[T_TANULOERTEKELES] WITH CHECK CHECK CONSTRAINT [FK_4025662_4025660];

ALTER TABLE [dbo].[T_TANITASIORA] WITH CHECK CHECK CONSTRAINT [FK_4025608_4025607];

ALTER TABLE [dbo].[T_HAZIFELADATOK] WITH CHECK CHECK CONSTRAINT [FK_4028120_4028118];

ALTER TABLE [dbo].[T_TANTARGY] WITH CHECK CHECK CONSTRAINT [FK_4025408_4025407];

ALTER TABLE [dbo].[T_TANTARGY] WITH CHECK CHECK CONSTRAINT [FK_402539902_402539900];

ALTER TABLE [dbo].[T_TANTARGY] WITH CHECK CHECK CONSTRAINT [FK_402539905_402539903];

ALTER TABLE [dbo].[T_TANTARGY] WITH CHECK CHECK CONSTRAINT [FK_4025399_4025404];

ALTER TABLE [dbo].[T_OGFOGLALKOZAS] WITH CHECK CHECK CONSTRAINT [FK_4027782_4027781];

ALTER TABLE [dbo].[T_OGTANTARGYFOGLALTSAG] WITH CHECK CHECK CONSTRAINT [FK_4027786_4027784];

ALTER TABLE [dbo].[T_TANMENET] WITH CHECK CHECK CONSTRAINT [FK_4025597_4025595];

ALTER TABLE [dbo].[T_TANARITANTARGY] WITH CHECK CHECK CONSTRAINT [FK_4025946_4025944];

ALTER TABLE [dbo].[T_ORARENDIORA] WITH CHECK CHECK CONSTRAINT [FK_4026321_4026319];

ALTER TABLE [dbo].[T_TANULOMENTESSEG] WITH CHECK CHECK CONSTRAINT [FK_4025776_4025775];

ALTER TABLE [dbo].[T_OGTEREM_TANTARGY] WITH CHECK CHECK CONSTRAINT [FK_4027774_4027772];



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_TANTARGY', 'T_TANTARGY_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

EXEC dev.sp_Global_GenerateAsyncAuditProcedureAll
GO

EXEC dev.sp_Global_GenerateAsyncAuditAuditPocessing
GO

ALTER QUEUE auditLog.[AuditQueue]
WITH ACTIVATION
( 
    STATUS = ON,
    PROCEDURE_NAME = auditLog.usp_AuditProcessing,
    MAX_QUEUE_READERS = 10,
    EXECUTE AS 'Kreta_tech_user'
);

GO
