﻿UPDATE csr SET C_NEV=CONCAT(C_NEV,' (',rn,')')
FROM (
  SELECT 
     ROW_NUMBER() OVER (PARTITION BY csr.C_TANEVID,csr.C_NEV ORDER BY csr.C_AKTIV DESC, csr.CREATED ASC) rn
    ,csr.ID
  FROM(
    SELECT 
       C_TANEVID
      ,C_NEV 
    FROM T_CSENGETESIREND csr
    WHERE csr.TOROLT='F'
    GROUP BY C_TANEVID,C_NEV
    HAVING COUNT(*)>1) x
    INNER JOIN T_CSENGETESIREND csr ON csr.C_TANEVID=x.C_TANEVID AND csr.C_NEV=x.C_NEV AND TOROLT='F') y
  INNER JOIN T_CSENGETESIREND csr ON csr.ID=y.ID AND y.rn>1

GO

DROP INDEX IF EXISTS T_CSENGETESIREND.UK_4025457_4026183
GO
DROP INDEX IF EXISTS T_CSENGETESIREND.NCU_Csengetesirend_TanevId_IntezmenyId_Nev
GO
CREATE UNIQUE INDEX NCU_Csengetesirend_TanevId_IntezmenyId_Nev
  ON T_CSENGETESIREND (C_TANEVID,C_INTEZMENYID,C_NEV)
  WHERE TOROLT='F'
  WITH (FILLFACTOR = 80)
GO