Filling the gaps in values of IDENTITY column

后端 未结 4 1630
南旧
南旧 2020-12-19 20:15

I have a table with an IDENTITY column

[Id] int IDENTITY(1, 1) NOT NULL

After some rows beeing added/removed I end with gaps in Id values:<

4条回答
  •  隐瞒了意图╮
    2020-12-19 20:47

    I think it's pretty easy to create a 2nd table with the same schema, import all the data (except for the identity column of course; let the 2nd table start renumbering) from the first table, drop the first table and rename the 2nd to the original name.

    Easiness may be in question if you'd have a ton of FK relationships to rebuild with other tables etc.

提交回复
热议问题