﻿--Migration
WITH DuplicatedCTE AS (  
   SELECT *, ROW_NUMBER() OVER (PARTITION BY ic.C_INTEZMENYID, ic.C_CONFIGTIPUSID ORDER BY ic.CREATED) AS RN  
   FROM T_INTEZMENYCONFIG ic
   WHERE ic.TOROLT = 'F'
)  

DELETE FROM DuplicatedCTE WHERE RN > 1
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'NCU_IntezmenyConfig_IntezmenyId_ConfigId') BEGIN
  CREATE UNIQUE NONCLUSTERED INDEX NCU_IntezmenyConfig_IntezmenyId_ConfigId 
    ON dbo.T_INTEZMENYCONFIG (C_INTEZMENYID, C_CONFIGTIPUSID) 
  WHERE TOROLT = 'F'
  WITH (FILLFACTOR = 80)
END
GO
