Reset AutoIncrement in SQL Server after Delete(删除后重置 SQL Server 中的自动增量)
问题描述
我从 SQL Server 数据库的表中删除了一些记录.
I've deleted some records from a table in a SQL Server database.
表中的 ID 如下所示:
The IDs in the table look like this:
9910010112001201……
99 100 101 1200 1201...
我想删除后面的记录(ID > 1200),然后我想重置自动增量,这样下一个自动生成的 ID 将是 102.所以我的记录是连续的,有没有办法在 SQL Server 中做到这一点?
I want to delete the later records (IDs >1200), then I want to reset the auto increment so the next autogenerated ID will be 102. So my records are sequential, Is there a way to do this in SQL Server?
推荐答案
发出以下命令以重新播种 mytable 以从 1 开始:
Issue the following command to reseed mytable to start at 1:
DBCC CHECKIDENT (mytable, RESEED, 0)
在在线书籍(BOL、SQL 帮助)中阅读有关它的信息.还要注意您的记录不要高于您设置的种子.
Read about it in the Books on Line (BOL, SQL help). Also be careful that you don't have records higher than the seed you are setting.
这篇关于删除后重置 SQL Server 中的自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:删除后重置 SQL Server 中的自动增量


- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01