﻿--Migration
;WITH cte AS (
  SELECT ID, ROW_NUMBER()  OVER(PARTITION BY C_FELHASZNALOID ORDER BY CREATED) AS RN, TOROLT, LASTCHANGED, MODIFIER FROM T_USERPROFILE up
)

UPDATE cte SET TOROLT = 'F', LASTCHANGED = GETDATE(), MODIFIER = 0
WHERE RN >= 2
GO


IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_UserProfile_FelhasznaloId') BEGIN
  CREATE INDEX NCU_UserProfile_FelhasznaloId
  ON T_USERPROFILE (
     C_FELHASZNALOID
  )
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
END
GO

IF COL_LENGTH('dbo.T_DKT_FELADAT', 'ELOZOTANEVIREKORDID') IS NULL BEGIN
  ALTER TABLE dbo.T_DKT_FELADAT ADD ELOZOTANEVIREKORDID int
  EXEC dev.uspCreateSchemaViews 'T_DKT_FELADAT'
  PRINT 'T_DKT_FELADAT COLUMN ADDED'
END
GO

IF COL_LENGTH('dbo.T_JUTTATAS', 'ELOZOTANEVIREKORDID') IS NULL BEGIN
  ALTER TABLE dbo.T_JUTTATAS ADD ELOZOTANEVIREKORDID int
  EXEC dev.uspCreateSchemaViews 'T_JUTTATAS'
  PRINT 'T_JUTTATAS COLUMN ADDED'
END
GO

IF COL_LENGTH('dbo.T_TANULOTANTARGYATLAG', 'ELOZOTANEVIREKORDID') IS NULL BEGIN
  ALTER TABLE dbo.T_TANULOTANTARGYATLAG ADD ELOZOTANEVIREKORDID int
  EXEC dev.uspCreateSchemaViews 'T_TANULOTANTARGYATLAG'
  PRINT 'T_TANULOTANTARGYATLAG COLUMN ADDED'
END
GO

IF COL_LENGTH('dbo.T_JUTTATASTIPUS', 'ELOZOTANEVIREKORDID') IS NULL BEGIN
  ALTER TABLE dbo.T_JUTTATASTIPUS ADD ELOZOTANEVIREKORDID int
  EXEC dev.uspCreateSchemaViews 'T_JUTTATASTIPUS'
  PRINT 'T_JUTTATASTIPUS COLUMN ADDED'
END
GO

IF COL_LENGTH('dbo.T_JUTTATASTIPUS', 'ELOZOTANEVIREKORDIDA') IS NULL BEGIN
  ALTER TABLE dbo.T_JUTTATASTIPUS ADD ELOZOTANEVIREKORDIDA int
  EXEC dev.uspCreateSchemaViews 'T_JUTTATASTIPUS'
  PRINT 'T_JUTTATASTIPUS COLUMN ADDED'
END
GO

UPDATE T_GONDVISELO SET C_ISCOVIDBEJELENTO = 'F'
WHERE [C_ISCOVIDBEJELENTO] IS NULL
GO