在SQL Server中删除记录后重置身份种子 [英] Reset identity seed after deleting records in SQL Server
问题描述
我已将记录插入到SQL Server数据库表中.该表已定义了主键,并且自动增量标识种子设置为是".这样做主要是因为在SQL Azure中,每个表都必须定义一个主键和标识.
I have inserted records into a SQL Server database table. 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.
但是由于我必须从表中删除一些记录,所以这些表的标识种子将受到干扰,索引列(以1为增量自动生成)将受到干扰.
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.
删除记录后如何重置标识列,以使列具有按升序排列的顺序?
标识列在数据库中的任何地方都不用作外键.
The identity column is not used as a foreign key anywhere in database.
推荐答案
c0> 管理命令用于重置身份计数器.命令语法为:
The DBCC CHECKIDENT
management command is used to reset identity counter. The command syntax is:
DBCC CHECKIDENT (table_name [, { NORESEED | { RESEED [, new_reseed_value ]}}])
[ WITH NO_INFOMSGS ]
示例:
DBCC CHECKIDENT ('[TestTable]', RESEED, 0);
GO
Azure SQL数据库的早期版本不支持此功能,但现在支持.
It was not supported in previous versions of the Azure SQL Database but is supported now.
感谢所罗门群岛Rutzky docs 现在已修复.
这篇关于在SQL Server中删除记录后重置身份种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!