如何按顺序获取标识列值 [英] how to get identity colums values sequentially
本文介绍了如何按顺序获取标识列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
某些连续的vales被删除我想使用那些值
some sequential vales are deleted i want to use those values
推荐答案
你不能,暂时禁用身份 - 如果你在多用户环境?如果两个人决定同时重新使用旧号码,你可能会回来同样的问题,你试图使用身份字段来避免....
如果你需要一个反映记录数量中行位置的数字,那么使用ROW_NUMBER函数:
You can''t, without disabling the identity temporarily - and what if you are in a multiuser environment? If two people decide to re-use the old number at the same time, you could be back with teh same problem you are trying to use identity fields to avoid....
If you need a number which reflects a rows position in the number of records, then use the ROW_NUMBER function:
SELECT Id, Customer, date, Value,
@@ROWCOUNT as 'Row Count',
ROW_NUMBER() OVER (ORDER BY Id) AS 'Row Number'
FROM Customers
这会随着您插入和删除记录而有所不同,但身份值可以保留安全而独特。
That will vary as you insert and remove records, but the identity value can remain safe and unique.
这篇关于如何按顺序获取标识列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文