﻿GO
UPDATE T_FELHASZNALOBELEPES SET TOROLT = 'T' WHERE C_BEJELENTKEZESINEV = 'KRETA_TECHNICAL_FORI' AND C_TANEVID IN (
 SELECT ID FROM T_TANEV WHERE C_AKTIV = 'F'
)


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


GO
ALTER TABLE [dbo].[T_GONDVISELO] DROP CONSTRAINT [FK_4025169_4025177];


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


GO
ALTER TABLE [dbo].[T_GONDVISELO] DROP CONSTRAINT [FK_4025181_4025180];


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


GO
ALTER TABLE [dbo].[T_GONDVISELO] DROP CONSTRAINT [FK_402516902_402516900];


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


GO
ALTER TABLE [dbo].[T_GONDVISELO] DROP CONSTRAINT [FK_402516905_402516903];


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] DROP CONSTRAINT [FK_4025031_4025029];


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] DROP CONSTRAINT [FK_4025187_4025186];


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] DROP CONSTRAINT [FK_402502202_402502200];


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] DROP CONSTRAINT [FK_402502205_402502203];


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


GO
ALTER TABLE [dbo].[T_JELSZOVISSZAALLITAS] DROP CONSTRAINT [FK_4028152_4028151];


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


GO
ALTER TABLE [dbo].[T_TANULOERTEKELESLATTAMOZAS] DROP CONSTRAINT [FK_4028060_4028058];


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


GO
ALTER TABLE [dbo].[T_TANULOESEMENYLATTAMOZAS] DROP CONSTRAINT [FK_4028056_4028055];


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


GO
ALTER TABLE [dbo].[T_TANULOMULASZTASLATTAMOZAS] DROP CONSTRAINT [FK_4028063_4028061];


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


GO
ALTER TABLE [dbo].[T_EMAIL] DROP CONSTRAINT [FK_4025224_4025222];


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


GO
ALTER TABLE [dbo].[T_DIAKIGAZOLVANYIGENYLES] DROP CONSTRAINT [FK_4025785_4025784];


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


GO
ALTER TABLE [dbo].[T_TELEFON] DROP CONSTRAINT [FK_4025221_4025219];


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_GONDVISELOERTESITES] DROP CONSTRAINT [FK_4025878_4025876];


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


GO
ALTER TABLE [dbo].[T_OLDALLATOGATOTTSAG] DROP CONSTRAINT [FK_4026047_4026046];


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPESTORTENET] DROP CONSTRAINT [FK_4028159_4028157];


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


GO
ALTER TABLE [dbo].[T_JOGOSULTGONDVISELOK_HOZZAREN] DROP CONSTRAINT [FK_4026216_4026215];


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


GO
ALTER TABLE [dbo].[T_FALIUJSAGLATOGATTOTSAG] DROP CONSTRAINT [FK_4025824_4025822];


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


GO
ALTER TABLE [dbo].[T_IKTATOTTDOKUMENTUMOK] DROP CONSTRAINT [FK_4026219_4026218];


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


GO
ALTER TABLE [dbo].[T_IKTATOTTDOKUMENTUMOK] DROP CONSTRAINT [FK_4026222_4026221];


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


GO
ALTER TABLE [dbo].[T_CIM] DROP CONSTRAINT [FK_4025184_4025183];


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


GO
BEGIN TRANSACTION;

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

SET XACT_ABORT ON;

CREATE TABLE [dbo].[tmp_ms_xx_T_GONDVISELO] (
    [ID]                        INT            IDENTITY (1, 1) NOT NULL,
    [C_AKTIV]                   CHAR (1)       DEFAULT ('T') NULL,
    [C_GONDVISELESKEZDETE]      DATETIME       NULL,
    [C_GONDVISELESVEGE]         DATETIME       NULL,
    [C_GYERMEKETEGYEDULNEVELO]  CHAR (1)       DEFAULT ('F') NULL,
    [C_NEV]                     NVARCHAR (200) NOT NULL,
    [C_NYUGDIJAS]               CHAR (1)       DEFAULT ('F') NULL,
    [C_ROKONSAGFOKA]            INT            NOT NULL,
    [C_ISEMAILERTESITES]        CHAR (1)       DEFAULT ('F') NULL,
    [C_ISTORVENYESKEPVISELO]    CHAR (1)       DEFAULT ('F') NOT NULL,
    [C_ISCSOKKENTETTGONDVISELO] CHAR (1)       DEFAULT ('F') NOT NULL,
    [C_TANULOID]                INT            NOT 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_40251691] PRIMARY KEY CLUSTERED ([ID] ASC)
);

IF EXISTS (SELECT TOP 1 1 
           FROM   [dbo].[T_GONDVISELO])
    BEGIN
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_GONDVISELO] ON;
        INSERT INTO [dbo].[tmp_ms_xx_T_GONDVISELO] ([ID], [C_AKTIV], [C_GONDVISELESKEZDETE], [C_GONDVISELESVEGE], [C_GYERMEKETEGYEDULNEVELO], [C_NEV], [C_NYUGDIJAS], [C_ROKONSAGFOKA], [C_ISEMAILERTESITES], [C_ISTORVENYESKEPVISELO], [C_TANULOID], [C_INTEZMENYID], [C_TANEVID], [TOROLT], [SERIAL], [LASTCHANGED], [CREATED], [MODIFIER], [CREATOR], [ELOZOTANEVIREKORDID], [NNID])
        SELECT   [ID],
                 [C_AKTIV],
                 [C_GONDVISELESKEZDETE],
                 [C_GONDVISELESVEGE],
                 [C_GYERMEKETEGYEDULNEVELO],
                 [C_NEV],
                 [C_NYUGDIJAS],
                 [C_ROKONSAGFOKA],
                 [C_ISEMAILERTESITES],
                 [C_ISTORVENYESKEPVISELO],
                 [C_TANULOID],
                 [C_INTEZMENYID],
                 [C_TANEVID],
                 [TOROLT],
                 [SERIAL],
                 [LASTCHANGED],
                 [CREATED],
                 [MODIFIER],
                 [CREATOR],
                 [ELOZOTANEVIREKORDID],
                 [NNID]
        FROM     [dbo].[T_GONDVISELO]
        ORDER BY [ID] ASC;
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_GONDVISELO] OFF;
    END

DROP TABLE [dbo].[T_GONDVISELO];

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_T_GONDVISELO]', N'T_GONDVISELO';

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_constraint_PK_T_40251691]', N'PK_T_4025169', N'OBJECT';

COMMIT TRANSACTION;

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;


GO
PRINT N'Creating [dbo].[T_GONDVISELO].[I_T_4025169_4025177]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025169_4025177]
    ON [dbo].[T_GONDVISELO]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_ROKONSAGFOKA] ASC);


GO
PRINT N'Creating [dbo].[T_GONDVISELO].[I_T_4025181_4025180]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025181_4025180]
    ON [dbo].[T_GONDVISELO]([C_TANULOID] ASC);


GO
PRINT N'Creating [dbo].[T_GONDVISELO].[I_T_402516902_402516900]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402516902_402516900]
    ON [dbo].[T_GONDVISELO]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_GONDVISELO].[I_T_402516905_402516903]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402516905_402516903]
    ON [dbo].[T_GONDVISELO]([C_TANEVID] ASC);


GO
PRINT N'Creating [dbo].[T_GONDVISELO].[NCI_Gondviselo_TanuloId_IntezmenyId_TanevId]...';


GO
CREATE NONCLUSTERED INDEX [NCI_Gondviselo_TanuloId_IntezmenyId_TanevId]
    ON [dbo].[T_GONDVISELO]([C_TANULOID] ASC, [C_INTEZMENYID] ASC, [C_TANEVID] ASC)
    INCLUDE([C_NEV]) WHERE ([TOROLT]='F') WITH (FILLFACTOR = 80);


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


GO
BEGIN TRANSACTION;

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

SET XACT_ABORT ON;

CREATE TABLE [dbo].[tmp_ms_xx_T_FELHASZNALOBELEPES] (
    [ID]                          INT            IDENTITY (1, 1) NOT NULL,
    [C_KOTELEZOVALTOZTATNI]       CHAR (1)       DEFAULT ('T') NULL,
    [C_MEGHIUSULTBELEPESEK]       INT            NULL,
    [C_UTOLSOBELEPES]             DATETIME       NULL,
    [C_JELSZO]                    NVARCHAR (64)  NULL,
    [C_JELSZOVALTOZTATASIDEJE]    DATETIME       NULL,
    [C_SO]                        NVARCHAR (64)  NULL,
    [C_BEJELENTKEZESINEV]         NVARCHAR (255) NOT NULL,
    [C_NEPTUNNAPLOJELSZO]         NVARCHAR (64)  NULL,
    [C_GUID]                      NVARCHAR (36)  NOT NULL,
    [C_ELFOGADOTTGDPRNYILATKOZAT] CHAR (1)       DEFAULT ('F') NOT NULL,
    [C_GDPRELFOGADASDATUMA]       DATETIME       NULL,
    [C_FELHASZNALOID]             INT            NOT NULL,
    [C_GONDVISELOID]              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_40250221] PRIMARY KEY CLUSTERED ([ID] ASC)
);

IF EXISTS (SELECT TOP 1 1 
           FROM   [dbo].[T_FELHASZNALOBELEPES])
    BEGIN
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_FELHASZNALOBELEPES] ON;
        INSERT INTO [dbo].[tmp_ms_xx_T_FELHASZNALOBELEPES] ([ID], [C_KOTELEZOVALTOZTATNI], [C_MEGHIUSULTBELEPESEK], [C_UTOLSOBELEPES], [C_JELSZO], [C_JELSZOVALTOZTATASIDEJE], [C_SO], [C_BEJELENTKEZESINEV], [C_NEPTUNNAPLOJELSZO], [C_GUID], [C_FELHASZNALOID], [C_GONDVISELOID], [C_INTEZMENYID], [C_TANEVID], [TOROLT], [SERIAL], [LASTCHANGED], [CREATED], [MODIFIER], [CREATOR], [ELOZOTANEVIREKORDID], [NNID])
        SELECT   [ID],
                 [C_KOTELEZOVALTOZTATNI],
                 [C_MEGHIUSULTBELEPESEK],
                 [C_UTOLSOBELEPES],
                 [C_JELSZO],
                 [C_JELSZOVALTOZTATASIDEJE],
                 [C_SO],
                 [C_BEJELENTKEZESINEV],
                 [C_NEPTUNNAPLOJELSZO],
                 [C_GUID],
                 [C_FELHASZNALOID],
                 [C_GONDVISELOID],
                 [C_INTEZMENYID],
                 [C_TANEVID],
                 [TOROLT],
                 [SERIAL],
                 [LASTCHANGED],
                 [CREATED],
                 [MODIFIER],
                 [CREATOR],
                 [ELOZOTANEVIREKORDID],
                 [NNID]
        FROM     [dbo].[T_FELHASZNALOBELEPES]
        ORDER BY [ID] ASC;
        SET IDENTITY_INSERT [dbo].[tmp_ms_xx_T_FELHASZNALOBELEPES] OFF;
    END

--[T_FELHASZNALOBELEPES].C_ISCSOKKENTETTGONDVISELO értékeit a T_GONDVISELO táblába mozgatni
UPDATE g
SET g.C_ISCSOKKENTETTGONDVISELO = ISNULL(fb.C_ISCSOKKENTETTGONDVISELO, 'F')
FROM T_GONDVISELO g
LEFT JOIN T_FELHASZNALOBELEPES fb ON fb.C_GONDVISELOID = g.ID AND fb.TOROLT = 'F'
WHERE g.TOROLT = 'F'


DROP TABLE [dbo].[T_FELHASZNALOBELEPES];

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_T_FELHASZNALOBELEPES]', N'T_FELHASZNALOBELEPES';

EXECUTE sp_rename N'[dbo].[tmp_ms_xx_constraint_PK_T_40250221]', N'PK_T_4025022', N'OBJECT';

COMMIT TRANSACTION;

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;


GO
PRINT N'Creating [dbo].[T_FELHASZNALOBELEPES].[I_T_4025031_4025029]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025031_4025029]
    ON [dbo].[T_FELHASZNALOBELEPES]([C_FELHASZNALOID] ASC);


GO
PRINT N'Creating [dbo].[T_FELHASZNALOBELEPES].[I_T_4025187_4025186]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4025187_4025186]
    ON [dbo].[T_FELHASZNALOBELEPES]([C_GONDVISELOID] ASC);


GO
PRINT N'Creating [dbo].[T_FELHASZNALOBELEPES].[I_T_402502202_402502200]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402502202_402502200]
    ON [dbo].[T_FELHASZNALOBELEPES]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_FELHASZNALOBELEPES].[I_T_402502205_402502203]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402502205_402502203]
    ON [dbo].[T_FELHASZNALOBELEPES]([C_TANEVID] ASC);


GO
PRINT N'Creating [dbo].[T_FELHASZNALOBELEPES].[UK_4025364]...';


GO
CREATE UNIQUE NONCLUSTERED INDEX [UK_4025364]
    ON [dbo].[T_FELHASZNALOBELEPES]([C_BEJELENTKEZESINEV] ASC, [C_INTEZMENYID] ASC, [C_TANEVID] ASC) WHERE ([TOROLT]='F');


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


GO
CREATE TABLE [dbo].[T_JELSZOMODOSITASLINK] (
    [ID]                          INT           IDENTITY (1, 1) NOT NULL,
    [C_AZONOSITO]                 NVARCHAR (36) NOT NULL,
    [C_LETREHOZASDATUMA]          DATETIME      NOT NULL,
    [C_PROBALKOZASOKSZAMA]        INT           NOT NULL,
    [C_ISSZULETESIDATUMVALIDACIO] CHAR (1)      NOT NULL,
    [C_FELHASZNALOID]             INT           NOT NULL,
    [C_GONDVISELOID]              INT           NULL,
    [C_INTEZMENYID]               INT           NOT NULL,
    [C_TANEVID]                   INT           NOT NULL,
    [TOROLT]                      CHAR (1)      NOT NULL,
    [SERIAL]                      INT           NOT NULL,
    [LASTCHANGED]                 DATETIME      NOT NULL,
    [CREATED]                     DATETIME      NOT NULL,
    [MODIFIER]                    INT           NULL,
    [CREATOR]                     INT           NULL,
    [ELOZOTANEVIREKORDID]         INT           NULL,
    [NNID]                        INT           NULL,
    CONSTRAINT [PK_T_4028513] PRIMARY KEY CLUSTERED ([ID] ASC)
);


GO
PRINT N'Creating [dbo].[T_JELSZOMODOSITASLINK].[I_T_4028520_4028518]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028520_4028518]
    ON [dbo].[T_JELSZOMODOSITASLINK]([C_FELHASZNALOID] ASC);


GO
PRINT N'Creating [dbo].[T_JELSZOMODOSITASLINK].[I_T_4028523_4028521]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028523_4028521]
    ON [dbo].[T_JELSZOMODOSITASLINK]([C_GONDVISELOID] ASC);


GO
PRINT N'Creating [dbo].[T_JELSZOMODOSITASLINK].[I_T_402851302_402851300]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402851302_402851300]
    ON [dbo].[T_JELSZOMODOSITASLINK]([C_INTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_JELSZOMODOSITASLINK].[I_T_402851305_402851303]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402851305_402851303]
    ON [dbo].[T_JELSZOMODOSITASLINK]([C_TANEVID] ASC);


GO
PRINT N'Creating unnamed constraint on [dbo].[T_JELSZOMODOSITASLINK]...';


GO
ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK]
    ADD DEFAULT ('F') FOR [TOROLT];


GO
PRINT N'Creating unnamed constraint on [dbo].[T_JELSZOMODOSITASLINK]...';


GO
ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK]
    ADD DEFAULT ((0)) FOR [C_PROBALKOZASOKSZAMA];


GO
PRINT N'Creating unnamed constraint on [dbo].[T_JELSZOMODOSITASLINK]...';


GO
ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK]
    ADD DEFAULT ((0)) FOR [SERIAL];


GO
PRINT N'Creating unnamed constraint on [dbo].[T_JELSZOMODOSITASLINK]...';


GO
ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK]
    ADD DEFAULT (getdate()) FOR [LASTCHANGED];


GO
PRINT N'Creating unnamed constraint on [dbo].[T_JELSZOMODOSITASLINK]...';


GO
ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK]
    ADD DEFAULT (getdate()) FOR [CREATED];


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH NOCHECK
    ADD CONSTRAINT [FK_4025031_4025029] FOREIGN KEY ([C_FELHASZNALOID]) REFERENCES [dbo].[T_FELHASZNALO] ([ID]);


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_JELSZOVISSZAALLITAS] WITH NOCHECK
    ADD CONSTRAINT [FK_4028152_4028151] FOREIGN KEY ([C_FELHASZNALOBELEPESID]) REFERENCES [dbo].[T_FELHASZNALOBELEPES] ([ID]);


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_GONDVISELO] WITH NOCHECK
    ADD CONSTRAINT [FK_4025169_4025177] FOREIGN KEY ([C_ROKONSAGFOKA], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_ROKONSAGIFOK] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


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


GO
ALTER TABLE [dbo].[T_GONDVISELO] WITH NOCHECK
    ADD CONSTRAINT [FK_4025181_4025180] FOREIGN KEY ([C_TANULOID]) REFERENCES [dbo].[T_TANULO] ([ID]);


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_DIAKIGAZOLVANYIGENYLES] WITH NOCHECK
    ADD CONSTRAINT [FK_4025785_4025784] FOREIGN KEY ([C_IGENYLOGONDVISELOID]) REFERENCES [dbo].[T_GONDVISELO] ([ID]);


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


GO
ALTER TABLE [dbo].[T_TELEFON] WITH NOCHECK
    ADD CONSTRAINT [FK_4025221_4025219] FOREIGN KEY ([C_GONDVISELOID]) REFERENCES [dbo].[T_GONDVISELO] ([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'Creating [dbo].[FK_4025878_4025876]...';


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_JOGOSULTGONDVISELOK_HOZZAREN] WITH NOCHECK
    ADD CONSTRAINT [FK_4026216_4026215] FOREIGN KEY ([C_JOGOSULTGONDVISELOKID]) REFERENCES [dbo].[T_GONDVISELO] ([ID]);


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


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


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


GO
ALTER TABLE [dbo].[T_IKTATOTTDOKUMENTUMOK] WITH NOCHECK
    ADD CONSTRAINT [FK_4026219_4026218] FOREIGN KEY ([C_DOKPARTNERGONDVISELOID]) REFERENCES [dbo].[T_GONDVISELO] ([ID]);


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


GO
ALTER TABLE [dbo].[T_IKTATOTTDOKUMENTUMOK] WITH NOCHECK
    ADD CONSTRAINT [FK_4026222_4026221] FOREIGN KEY ([C_FELTOLTOGONDVISELOID]) REFERENCES [dbo].[T_GONDVISELO] ([ID]);


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


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


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


GO
ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK] WITH NOCHECK
    ADD CONSTRAINT [FK_4028520_4028518] FOREIGN KEY ([C_FELHASZNALOID]) REFERENCES [dbo].[T_FELHASZNALO] ([ID]);


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH NOCHECK
    ADD CONSTRAINT [CK_FelhasznaloBelepes_GuidValidation] CHECK ([dbo].[fnGuidValidation]([C_BEJELENTKEZESINEV],[C_INTEZMENYID])<=(1));


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH NOCHECK
    ADD CONSTRAINT [CK_FelhasznaloBelepes_SoNullValidation] CHECK (NOT ([C_JELSZO] IS NOT NULL AND [C_SO] IS NULL AND [C_NEPTUNNAPLOJELSZO] IS NULL));


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH NOCHECK
    ADD CONSTRAINT [CK_FelhasznaloBelepes_PasswordValidation] CHECK (NOT ([C_JELSZO] IS NOT NULL AND len([C_JELSZO])<>(28) AND NOT [C_JELSZO] like '%='));


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


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


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


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


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


GO
CREATE VIEW [dbo].T_JELSZOMODOSITASLINK_OSSZES
        AS
        SELECT *
        FROM dbo.T_JELSZOMODOSITASLINK
GO
PRINT N'Refreshing [dbo].[fnGetDokumentumTanuloOrGondviseloCim]...';


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH CHECK CHECK CONSTRAINT [FK_4025031_4025029];

ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH CHECK CHECK CONSTRAINT [FK_4025187_4025186];

ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH CHECK CHECK CONSTRAINT [FK_402502202_402502200];

ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH CHECK CHECK CONSTRAINT [FK_402502205_402502203];

ALTER TABLE [dbo].[T_JELSZOVISSZAALLITAS] WITH CHECK CHECK CONSTRAINT [FK_4028152_4028151];

ALTER TABLE [dbo].[T_TANULOERTEKELESLATTAMOZAS] WITH CHECK CHECK CONSTRAINT [FK_4028060_4028058];

ALTER TABLE [dbo].[T_TANULOESEMENYLATTAMOZAS] WITH CHECK CHECK CONSTRAINT [FK_4028056_4028055];

ALTER TABLE [dbo].[T_TANULOMULASZTASLATTAMOZAS] WITH CHECK CHECK CONSTRAINT [FK_4028063_4028061];

ALTER TABLE [dbo].[T_EMAIL] WITH CHECK CHECK CONSTRAINT [FK_4025224_4025222];

ALTER TABLE [dbo].[T_GONDVISELO] WITH CHECK CHECK CONSTRAINT [FK_4025169_4025177];

ALTER TABLE [dbo].[T_GONDVISELO] WITH CHECK CHECK CONSTRAINT [FK_4025181_4025180];

ALTER TABLE [dbo].[T_GONDVISELO] WITH CHECK CHECK CONSTRAINT [FK_402516902_402516900];

ALTER TABLE [dbo].[T_GONDVISELO] WITH CHECK CHECK CONSTRAINT [FK_402516905_402516903];

ALTER TABLE [dbo].[T_DIAKIGAZOLVANYIGENYLES] WITH CHECK CHECK CONSTRAINT [FK_4025785_4025784];

ALTER TABLE [dbo].[T_TELEFON] WITH CHECK CHECK CONSTRAINT [FK_4025221_4025219];

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

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

ALTER TABLE [dbo].[T_GONDVISELOERTESITES] WITH CHECK CHECK CONSTRAINT [FK_4025878_4025876];

ALTER TABLE [dbo].[T_OLDALLATOGATOTTSAG] WITH CHECK CHECK CONSTRAINT [FK_4026047_4026046];

ALTER TABLE [dbo].[T_FELHASZNALOBELEPESTORTENET] WITH CHECK CHECK CONSTRAINT [FK_4028159_4028157];

ALTER TABLE [dbo].[T_JOGOSULTGONDVISELOK_HOZZAREN] WITH CHECK CHECK CONSTRAINT [FK_4026216_4026215];

ALTER TABLE [dbo].[T_FALIUJSAGLATOGATTOTSAG] WITH CHECK CHECK CONSTRAINT [FK_4025824_4025822];

ALTER TABLE [dbo].[T_IKTATOTTDOKUMENTUMOK] WITH CHECK CHECK CONSTRAINT [FK_4026219_4026218];

ALTER TABLE [dbo].[T_IKTATOTTDOKUMENTUMOK] WITH CHECK CHECK CONSTRAINT [FK_4026222_4026221];

ALTER TABLE [dbo].[T_CIM] WITH CHECK CHECK CONSTRAINT [FK_4025184_4025183];

ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK] WITH CHECK CHECK CONSTRAINT [FK_4028520_4028518];

ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK] WITH CHECK CHECK CONSTRAINT [FK_4028523_4028521];

ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK] WITH CHECK CHECK CONSTRAINT [FK_402851302_402851300];

ALTER TABLE [dbo].[T_JELSZOMODOSITASLINK] WITH CHECK CHECK CONSTRAINT [FK_402851305_402851303];

ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH CHECK CHECK CONSTRAINT [CK_FelhasznaloBelepes_GuidValidation];

ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH CHECK CHECK CONSTRAINT [CK_FelhasznaloBelepes_SoNullValidation];

ALTER TABLE [dbo].[T_FELHASZNALOBELEPES] WITH CHECK CHECK CONSTRAINT [CK_FelhasznaloBelepes_PasswordValidation];


GO
PRINT N'Update complete.';


GO
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_GONDVISELO', 'T_GONDVISELO_OSSZES'
					,'T_FELHASZNALOBELEPES', 'T_FELHASZNALOBELEPES_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

