删除 SQL Server 中的记录后重置标识种子 - Reset identity seed after deleting records in SQL Server

问题:

I have inserted records into a SQL Server database table.我已将记录插入到 SQL Server 数据库表中。 The table had a primary key defined and the auto increment identity seed is set to “Yes”.该表定义了一个主键,并且自动递增标识种子设置为“是”。 This is done primarily because in SQL Azure, each table has to have a primary key and identity defined.这样做主要是因为在 SQL Azure 中,每个表都必须定义一个主键和标识。

But since I have to delete some records from the table, the identity seed for those tables will be disturbed and the index column (which is auto-generated with an increment of 1) will get disturbed.但是由于我必须从表中删除一些记录,这些表的身份种子将受到干扰,并且索引列(自动生成的增量为 1)将受到干扰。

How can I reset the identity column after I deleted the records so that the column has sequence in ascending numerical order?删除记录后如何重置标识列,以便该列按数字升序排列?

The identity column is not used as a foreign key anywhere in database.身份列不用作数据库中任何地方的外键。


解决方案:

参考一: https://en.stackoom.com/question/1TZXi
参考二: https://stackoom.com/question/1TZXi
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章