删除后在SQL Server中重置自动增量 [英] Reset AutoIncrement in SQL Server after Delete

查看:113
本文介绍了删除后在SQL Server中重置自动增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从SQL Server数据库的表中删除了一些记录.现在,ID从101变为1200.我想再次删除记录,但我希望ID返回至102.在SQL Server中有没有办法做到这一点?

I've deleted some records from a table in a SQL Server database. Now the ID's go from 101 to 1200. I want to delete the records again, but I want the ID's to go back to 102. 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中重置自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆