简体   繁体   English

删除SQL中的记录后重置ID(主键)

[英]reset id(primary key) after deleting record in sql

How to reset the value after deleting particular record in sql using mvc2 使用MVC2在SQL中删除特定记录后如何重置值

ex records are: 1,2,3 deleted record:3 ex记录是:1,2,3已删除记录:3

now i am adding new record .it should have the id 3 not 4. what can i do for that?? 现在我要添加新记录。它应该具有ID 3而不是4。我该怎么办?

You can Reseed your table like this : 您可以像这样重新放置表格:

DBCC CHECKIDENT ('[YourTableName]', RESEED, 0);
GO

Well this is not a good idea if the id is associated with other tables it will make a big mess in your database, however I do not know in which context you want to use this so I leave it to your discretion. 好吧,如果id与其他表相关联,这将不是一个好主意,但是它将在您的数据库中造成很大的混乱,但是我不知道您要在哪个上下文中使用它,因此请您自行决定。 But instead of deleting you can disable the auto incrementer of the table in question, and write a bit to add the free ids. 但是您可以禁用有问题的表的自动递增器,而不是删除它,并写一些位以添加可用的ID。 Obs; Obs; Continues to be a bad idea! 仍然是一个坏主意!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM