且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server中的身份

更新时间:2023-02-07 13:45:17

这是设计使然,系统会维护IDENTITY列,并且当您删除记录,这是为了在其他地方维护引用完整性.

如果您需要递增值而没有漏洞,请尝试添加自己的列并保持自己的值.
This is by design, IDENTITY columns are maintained by the system and the value does not change when you delete records, this is to maintain referential integrity elsewhere.

If you need incrementing values without holes try adding your own column and maintaining the values your self.


引用:

http://msdn.microsoft.com/en-us/library/ms186775.aspx [ ^ ]
Refer:

http://msdn.microsoft.com/en-us/library/ms186775.aspx[^]


首先,我有一个问题.为什么需要更新标识列.标识列由SQL Server本身维护.如果您需要一个报告,例如在srno中显示记录而不破坏序列,则可以尝试以下代码.

First I have a question. Why do you need to update the identity columns. Identity columns are maintained by SQL Server itself. If you need a report like showing the records in srno without breaking the sequence, you can try below code.

Select Row_Number() over ( order by SrNo) as SrNo,Name,Mail from yourTableName