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


GO
ALTER TABLE [dbo].[T_NAPLOELLENORZES] DROP CONSTRAINT [FK_4025763_4025762];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025320_4025319];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025323_4025322];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025421_4025419];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_402529402_402529400];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_402529405_402529403];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025294_4025295];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025294_4027544];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025294_4027545];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025294_4027546];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025294_4027547];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_4025294_4028299];


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


GO
ALTER TABLE [dbo].[T_OSZTALY] DROP CONSTRAINT [FK_T_4025296_4025338];


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


GO
ALTER TABLE [dbo].[T_CSOPORT] DROP CONSTRAINT [FK_4026206_4026204];


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


GO
ALTER TABLE [dbo].[T_CSOPORTOK_OSZTALYOK] DROP CONSTRAINT [FK_4025318_4025316];


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


GO
BEGIN TRANSACTION;

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

SET XACT_ABORT ON;

CREATE TABLE [dbo].[tmp_ms_xx_T_OSZTALY] (
    [ID]                             INT             NOT NULL,
    [C_KEPZESIFORMA]                 INT             NOT NULL,
    [C_OSZTALYNAPLOLEIRASA]          NVARCHAR (MAX)  NULL,
    [C_OSZTALYNAPLOMEGNYITASA]       DATETIME        NULL,
    [C_OSZTALYNAPLOZARASA]           DATETIME        NULL,
    [C_AGAZAT]                       INT             NULL,
    [C_RESZSZAKKEPESITES]            INT             NULL,
    [C_SZAKKEPESITES]                INT             NULL,
    [C_SZAKMACSOPORT]                INT             NULL,
    [C_TECHNIKAIOSZTALY]             CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_GIMNAZIUMIEVFOLYAMTIPUSID]    INT             NULL,
    [C_GYOGYPEDAGOGIAI]              CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_KETTANNYELVU]                 CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_LOGOPEDIAI]                   CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_NEMZETISEGI]                  CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_NYELVIELOKESZITO]             CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_SPORT]                        CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_AJTEHETTSEGGONDOZOPROGRAM]    CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_AJPROGRAM]                    CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_VEGYESEVFOLYAMU]              CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_VEGYESSZAKKEPZESU]            CHAR (1)        DEFAULT ('F') NOT NULL,
    [C_SPECIALISJELLEMZO]            NVARCHAR (4000) NULL,
    [C_VEGYESEVFOLYAMUTANTERV]       NVARCHAR (1000) NULL,
    [C_OSZTALYPENZBANKSZAMLASZAMKED] NVARCHAR (1000) NULL,
    [C_OSZTALYPENZBANKSZAMLASZAMA]   NVARCHAR (26)   NULL,
    [C_VPOSENGEDELYEZETT]            CHAR (1)        DEFAULT ('F') NULL,
    [C_OSZTALYFONOKID]               INT             NULL,
    [C_OFOHELYETTESID]               INT             NULL,
    [C_TANTERVID]                    INT             NULL,
    [C_SZMKKEPVISELOHELYETTESID]     INT             NULL,
    [C_SZMKKEPVISELOID]              INT             NULL,
    [C_ALINTEZMENYID]                INT             NOT NULL,
    [C_ALTANEVID]                    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,
    [ELOZOTANEVIREKORDIDA]           INT             NULL,
    [NNID]                           INT             NULL,
    CONSTRAINT [tmp_ms_xx_constraint_PK_T_40252941] PRIMARY KEY CLUSTERED ([ID] ASC)
);

IF EXISTS (SELECT TOP 1 1 
           FROM   [dbo].[T_OSZTALY])
    BEGIN
        INSERT INTO [dbo].[tmp_ms_xx_T_OSZTALY] ([ID], [C_KEPZESIFORMA], [C_OSZTALYNAPLOLEIRASA], [C_OSZTALYNAPLOMEGNYITASA], [C_OSZTALYNAPLOZARASA], [C_AGAZAT], [C_RESZSZAKKEPESITES], [C_SZAKKEPESITES], [C_SZAKMACSOPORT], [C_TECHNIKAIOSZTALY], [C_GIMNAZIUMIEVFOLYAMTIPUSID], [C_GYOGYPEDAGOGIAI], [C_KETTANNYELVU], [C_LOGOPEDIAI], [C_NEMZETISEGI], [C_NYELVIELOKESZITO], [C_SPORT], [C_AJTEHETTSEGGONDOZOPROGRAM], [C_AJPROGRAM], [C_VEGYESEVFOLYAMU], [C_VEGYESSZAKKEPZESU], [C_SPECIALISJELLEMZO], [C_VEGYESEVFOLYAMUTANTERV], [C_OSZTALYFONOKID], [C_OFOHELYETTESID], [C_TANTERVID], [C_ALINTEZMENYID], [C_ALTANEVID], [TOROLT], [SERIAL], [LASTCHANGED], [CREATED], [MODIFIER], [CREATOR], [ELOZOTANEVIREKORDID], [ELOZOTANEVIREKORDIDA], [NNID])
        SELECT   [ID],
                 [C_KEPZESIFORMA],
                 [C_OSZTALYNAPLOLEIRASA],
                 [C_OSZTALYNAPLOMEGNYITASA],
                 [C_OSZTALYNAPLOZARASA],
                 [C_AGAZAT],
                 [C_RESZSZAKKEPESITES],
                 [C_SZAKKEPESITES],
                 [C_SZAKMACSOPORT],
                 [C_TECHNIKAIOSZTALY],
                 [C_GIMNAZIUMIEVFOLYAMTIPUSID],
                 [C_GYOGYPEDAGOGIAI],
                 [C_KETTANNYELVU],
                 [C_LOGOPEDIAI],
                 [C_NEMZETISEGI],
                 [C_NYELVIELOKESZITO],
                 [C_SPORT],
                 [C_AJTEHETTSEGGONDOZOPROGRAM],
                 [C_AJPROGRAM],
                 [C_VEGYESEVFOLYAMU],
                 [C_VEGYESSZAKKEPZESU],
                 [C_SPECIALISJELLEMZO],
                 [C_VEGYESEVFOLYAMUTANTERV],
                 [C_OSZTALYFONOKID],
                 [C_OFOHELYETTESID],
                 [C_TANTERVID],
                 [C_ALINTEZMENYID],
                 [C_ALTANEVID],
                 [TOROLT],
                 [SERIAL],
                 [LASTCHANGED],
                 [CREATED],
                 [MODIFIER],
                 [CREATOR],
                 [ELOZOTANEVIREKORDID],
                 [ELOZOTANEVIREKORDIDA],
                 [NNID]
        FROM     [dbo].[T_OSZTALY]
        ORDER BY [ID] ASC;
    END

DROP TABLE [dbo].[T_OSZTALY];

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_T_OSZTALY]', N'T_OSZTALY';

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_constraint_PK_T_40252941]', N'PK_T_4025294', N'OBJECT';

COMMIT TRANSACTION;

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025294_4025295]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025294_4025295]
    ON [dbo].[T_OSZTALY]([C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC, [C_KEPZESIFORMA] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025294_4027544]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025294_4027544]
    ON [dbo].[T_OSZTALY]([C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC, [C_AGAZAT] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025294_4027545]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025294_4027545]
    ON [dbo].[T_OSZTALY]([C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC, [C_RESZSZAKKEPESITES] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025294_4027546]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025294_4027546]
    ON [dbo].[T_OSZTALY]([C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC, [C_SZAKKEPESITES] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025294_4027547]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025294_4027547]
    ON [dbo].[T_OSZTALY]([C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC, [C_SZAKMACSOPORT] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025294_4028299]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025294_4028299]
    ON [dbo].[T_OSZTALY]([C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC, [C_GIMNAZIUMIEVFOLYAMTIPUSID] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025320_4025319]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025320_4025319]
    ON [dbo].[T_OSZTALY]([C_OSZTALYFONOKID] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025323_4025322]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025323_4025322]
    ON [dbo].[T_OSZTALY]([C_OFOHELYETTESID] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4025421_4025419]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025421_4025419]
    ON [dbo].[T_OSZTALY]([C_TANTERVID] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4028505_4028504]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028505_4028504]
    ON [dbo].[T_OSZTALY]([C_SZMKKEPVISELOHELYETTESID] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_4028508_4028507]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028508_4028507]
    ON [dbo].[T_OSZTALY]([C_SZMKKEPVISELOID] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_402529402_402529400]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402529402_402529400]
    ON [dbo].[T_OSZTALY]([C_ALINTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_OSZTALY].[I_T_402529405_402529403]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402529405_402529403]
    ON [dbo].[T_OSZTALY]([C_ALTANEVID] ASC);


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


GO
ALTER TABLE [dbo].[T_NAPLOELLENORZES] WITH NOCHECK
    ADD CONSTRAINT [FK_4025763_4025762] FOREIGN KEY ([C_OSZTALYID]) REFERENCES [dbo].[T_OSZTALY] ([ID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025320_4025319] FOREIGN KEY ([C_OSZTALYFONOKID]) REFERENCES [dbo].[T_ALKALMAZOTT] ([ID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025323_4025322] FOREIGN KEY ([C_OFOHELYETTESID]) REFERENCES [dbo].[T_ALKALMAZOTT] ([ID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025421_4025419] FOREIGN KEY ([C_TANTERVID]) REFERENCES [dbo].[T_TANTERV] ([ID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_402529402_402529400] FOREIGN KEY ([C_ALINTEZMENYID]) REFERENCES [dbo].[T_INTEZMENY] ([ID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_402529405_402529403] FOREIGN KEY ([C_ALTANEVID]) REFERENCES [dbo].[T_TANEV] ([ID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025294_4025295] FOREIGN KEY ([C_KEPZESIFORMA], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_TANTERVIJELLEG] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025294_4027544] FOREIGN KEY ([C_AGAZAT], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_AGAZATTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025294_4027545] FOREIGN KEY ([C_RESZSZAKKEPESITES], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_RESZSZAKKEPESITESTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025294_4027546] FOREIGN KEY ([C_SZAKKEPESITES], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_SZAKKEPESITESTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025294_4027547] FOREIGN KEY ([C_SZAKMACSOPORT], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_SZAKMACSOPORTTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4025294_4028299] FOREIGN KEY ([C_GIMNAZIUMIEVFOLYAMTIPUSID], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_GIMNAZIUMIEVFOLYAMTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_T_4025296_4025338] FOREIGN KEY ([ID]) REFERENCES [dbo].[T_OSZTALYCSOPORT] ([ID]);


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


GO
ALTER TABLE [dbo].[T_CSOPORT] WITH NOCHECK
    ADD CONSTRAINT [FK_4026206_4026204] FOREIGN KEY ([C_OSZTALYBONTASID]) REFERENCES [dbo].[T_OSZTALY] ([ID]);


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


GO
ALTER TABLE [dbo].[T_CSOPORTOK_OSZTALYOK] WITH NOCHECK
    ADD CONSTRAINT [FK_4025318_4025316] FOREIGN KEY ([C_OSZTALYOKID]) REFERENCES [dbo].[T_OSZTALY] ([ID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4028505_4028504] FOREIGN KEY ([C_SZMKKEPVISELOHELYETTESID]) REFERENCES [dbo].[T_GONDVISELO] ([ID]);


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


GO
ALTER TABLE [dbo].[T_OSZTALY] WITH NOCHECK
    ADD CONSTRAINT [FK_4028508_4028507] FOREIGN KEY ([C_SZMKKEPVISELOID]) REFERENCES [dbo].[T_GONDVISELO] ([ID]);


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


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


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


GO
ALTER TABLE [dbo].[T_NAPLOELLENORZES] WITH CHECK CHECK CONSTRAINT [FK_4025763_4025762];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025320_4025319];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025323_4025322];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025421_4025419];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_402529402_402529400];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_402529405_402529403];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025294_4025295];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025294_4027544];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025294_4027545];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025294_4027546];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025294_4027547];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4025294_4028299];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_T_4025296_4025338];

ALTER TABLE [dbo].[T_CSOPORT] WITH CHECK CHECK CONSTRAINT [FK_4026206_4026204];

ALTER TABLE [dbo].[T_CSOPORTOK_OSZTALYOK] WITH CHECK CHECK CONSTRAINT [FK_4025318_4025316];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4028505_4028504];

ALTER TABLE [dbo].[T_OSZTALY] WITH CHECK CHECK CONSTRAINT [FK_4028508_4028507];


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_OSZTALY', 'T_OSZTALY_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
