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


GO
ALTER TABLE [dbo].[T_TEREM]
    ADD [C_AR]                       INT           NULL,
        [C_BERBEADHATO]              CHAR (1)      DEFAULT ('F') NOT NULL,
        [C_FOGLALHATOIDOSZAKKEZDETE] DATETIME      NULL,
        [C_FOGLALHATOIDOSZAKVEGE]    DATETIME      NULL,
        [C_LEIRAS]                   NVARCHAR (20) NULL,
        [C_FOTOID]                   INT           NULL;


GO
PRINT N'Creating [dbo].[T_TEREM].[I_T_4028684_4028683]...';


GO
CREATE NONCLUSTERED INDEX [I_T_4028684_4028683]
    ON [dbo].[T_TEREM]([C_FOTOID] ASC);


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


GO
ALTER TABLE [dbo].[T_TEREM] WITH NOCHECK
    ADD CONSTRAINT [FK_4028684_4028683] FOREIGN KEY ([C_FOTOID]) REFERENCES [dbo].[T_UPLOADEDFILE] ([ID]);


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


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


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


GO
ALTER TABLE [dbo].[T_TEREM] WITH CHECK CHECK CONSTRAINT [FK_4028684_4028683];


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_TEREM', 'T_TEREM_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
