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 中的自动增量
基础教程推荐
- 什么是 orradiag_<user>文件夹? 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 在多列上分布任意行 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
