刪除 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章