How to find “holes” in a table

后端 未结 10 2220
野趣味
野趣味 2020-12-24 04:28

I recently inherited a database on which one of the tables has the primary key composed of encoded values (Part1*1000 + Part2).
I normalized that column, but I cannot ch

10条回答
  •  清酒与你
    2020-12-24 05:04

    from How do I find a "gap" in running counter with SQL?

    select
        MIN(ID)
    from (
        select
            100001 ID
        union all
        select
            [YourIdColumn]+1
        from
            [YourTable]
        where
            --Filter the rest of your key--
        ) foo
    left join
        [YourTable]
        on [YourIdColumn]=ID
        and --Filter the rest of your key--
    where
        [YourIdColumn] is null
    

提交回复
热议问题