﻿--Migration
UPDATE T_TANEV
SET C_AKTIVALHATOSAGKEZDETE = DATEADD(DAY, -9, C_KEZDONAP)

IF OBJECT_ID('CK_Tanev_AktivalhatosagKezdete', 'C') IS NULL BEGIN
 ALTER TABLE [dbo].[T_TANEV] WITH CHECK
   ADD CONSTRAINT [CK_Tanev_AktivalhatosagKezdete]
   CHECK (TOROLT = 'T' OR C_AKTIVALHATOSAGKEZDETE BETWEEN DATEADD(DAY, -30, C_KEZDONAP) AND C_KEZDONAP);
END

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'CU_TanuloTantargyAtlag_TanuloId_TantargyId_OktatasNevelesiFeladatId') BEGIN
   CREATE UNIQUE INDEX NCU_T_TANEV_C_IntezmenyId_Aktiv ON dbo.T_TANEV (C_INTEZMENYID) Where C_AKTIV = 'T' AND TOROLT = 'F'
END

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'CU_TanuloTantargyAtlag_TanuloId_TantargyId_OktatasNevelesiFeladatId') BEGIN
   CREATE UNIQUE INDEX NCU_T_TANEV_C_IntezmenyId_Kovetkezo ON dbo.T_TANEV (C_INTEZMENYID) Where C_KOVETKEZO = 'T' AND TOROLT = 'F'
END