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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_4026116_4026121];


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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_4026116_4026122];


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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_4026116_4026343];


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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_4026116_4026352];


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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_4026116_4026365];


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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_4026125_4026124];


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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_4026129_4026127];


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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_402611602_402611600];


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


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] DROP CONSTRAINT [FK_402611605_402611603];


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


GO
ALTER TABLE [dbo].[T_TOVABBIMUNKAUGYIADATOK] DROP CONSTRAINT [FK_4027558_4027561];


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


GO
ALTER TABLE [dbo].[T_TOVABBIMUNKAUGYIADATOK] DROP CONSTRAINT [FK_4027558_4027563];


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


GO
ALTER TABLE [dbo].[T_TOVABBIMUNKAUGYIADATOK] DROP CONSTRAINT [FK_4027558_4027566];


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


GO
ALTER TABLE [dbo].[T_TOVABBIMUNKAUGYIADATOK] DROP CONSTRAINT [FK_4027558_4027567];


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


GO
ALTER TABLE [dbo].[T_TOVABBIMUNKAUGYIADATOK] DROP CONSTRAINT [FK_4027571_4027569];


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


GO
ALTER TABLE [dbo].[T_TOVABBIMUNKAUGYIADATOK] DROP CONSTRAINT [FK_4027574_4027572];


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


GO
ALTER TABLE [dbo].[T_TOVABBIMUNKAUGYIADATOK] DROP CONSTRAINT [FK_402755802_402755800];


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


GO
ALTER TABLE [dbo].[T_TOVABBIMUNKAUGYIADATOK] DROP CONSTRAINT [FK_402755805_402755803];


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


GO
ALTER TABLE [dbo].[T_KEPESITES] DROP CONSTRAINT [FK_T_21038_4026357];


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


GO
ALTER TABLE [dbo].[T_KEPESITES] DROP CONSTRAINT [FK_402635302_402635300];


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


GO
ALTER TABLE [dbo].[T_KEPESITES] DROP CONSTRAINT [FK_402635305_402635303];


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


GO
DROP VIEW [dbo].[T_KEPESITES_OSSZES];


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


GO
DROP TABLE [dbo].[T_KEPESITES];


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


GO
CREATE TABLE [dbo].[T_BESOROLASIFOKOZATTIPUS] (
    [ID]              INT      NOT NULL,
    [C_ALINTEZMENYID] INT      NOT NULL,
    [C_ALTANEVID]     INT      NOT NULL,
    [TOROLT]          CHAR (1) NULL,
    [SERIAL]          INT      NULL,
    [LASTCHANGED]     DATETIME NULL,
    [CREATED]         DATETIME NULL,
    [MODIFIER]        INT      NULL,
    [CREATOR]         INT      NULL,
    CONSTRAINT [PK_T_4026353] PRIMARY KEY CLUSTERED ([ID] ASC, [C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC)
);


GO
PRINT N'Creating [dbo].[T_BESOROLASIFOKOZATTIPUS].[I_T_402635302_402635300]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402635302_402635300]
    ON [dbo].[T_BESOROLASIFOKOZATTIPUS]([C_ALINTEZMENYID] ASC);


GO
PRINT N'Creating [dbo].[T_BESOROLASIFOKOZATTIPUS].[I_T_402635305_402635303]...';


GO
CREATE NONCLUSTERED INDEX [I_T_402635305_402635303]
    ON [dbo].[T_BESOROLASIFOKOZATTIPUS]([C_ALTANEVID] ASC);


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


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


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


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


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


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


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


GO
ALTER TABLE [dbo].[T_BESOROLASIFOKOZATTIPUS] WITH NOCHECK
    ADD CONSTRAINT [FK_T_21038_4026357] FOREIGN KEY ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_DICTIONARYITEMBASE] ([ID], [C_INTEZMENYID], [C_TANEVID]);


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


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


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


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


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


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


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


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


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


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


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_BESOROLASIFOKOZATTIPUS] WITH CHECK CHECK CONSTRAINT [FK_T_21038_4026357];

ALTER TABLE [dbo].[T_BESOROLASIFOKOZATTIPUS] WITH CHECK CHECK CONSTRAINT [FK_402635302_402635300];

ALTER TABLE [dbo].[T_BESOROLASIFOKOZATTIPUS] WITH CHECK CHECK CONSTRAINT [FK_402635305_402635303];


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_BESOROLASIFOKOZATTIPUS', 'T_BESOROLASIFOKOZATTIPUS_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
