删除行后保持标识序列 [英] Maintain identity sequence after deleting row

查看:69
本文介绍了删除行后保持标识序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在删除Row后维护标识序列?



例如 - 如果标识列具有值 - 1,2,3,4。如果我删除第4行并尝试插入新行

它将以'5'作为标识值,但我想要'4'。那是什么步骤?



请让我知道...

How to Maintain identity sequence after deleting Row?

eg - if identity column has values - 1 ,2 ,3 ,4. if i delete 4th row and try to insert new row
it will take '5' as identity value, but instead i want '4'. what is the step for that?.

please let me know...

推荐答案

SQL-服务器删除截形和 - 补种身份/ [ ^ ]


这是一个坏主意,因为您可能会破坏使用标识列作为外键的任何表的引用完整性。



你为什么要这样做?可读性?确实没有充分的理由这样做,它与像Excel这样的行无关。事实上,使用术语行并不完全正确,它们是记录,它们恰好是按行显示的。它们不是行,直到你显示它们,在数据库中它们是记录。
This is a bad idea since you risk breaking referential integrity of any tables that use the identity column as a foreign key.

Why do you want to do this? Readability? There really isn't a good reason to do this, it has nothing to do with "rows" like Excel. In fact using the term "row" is not completely correct, they are records, they just happen to be displayed in rows. They aren't rows until you display them, in the database they are records.


你好,



我同意Ron ,但我是根据你的知识分享这个



要将下一个ID的值设置为1000



我可以使用这个命令:表名订单





DBCC CHECKIDENT(订单) ,RESEED,999)





问候,

Mubin
Hi,

I agree with Ron, but i am sharing this for your knowledge

To set the value of the next ID to be 1000,

I can use this command: Table name orders


DBCC CHECKIDENT (orders, RESEED, 999)


Regards,
Mubin


这篇关于删除行后保持标识序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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