• select

    ID = row_number() over (partition by TABLENAME order by COLNAME),

    TABLENAME,

    COLNAME

    from

    #temp;