分布式应用时,有时候单号会存在重复,可通过Sqlserver自带的序列功能对高并发的数据进行区分。例子如下:
select current_value from sys.sequences where name = 'Weight_Num'
declare @seqNum bigint
select @seqNum=next value for Weight_Num
print @seqNum
本文介绍了如何在分布式应用中利用Sqlserver的序列功能来生成不重复的编号,通过查询序列当前值并获取下一个值,确保在高并发环境下数据的唯一性。示例代码展示了如何获取和使用序列。
分布式应用时,有时候单号会存在重复,可通过Sqlserver自带的序列功能对高并发的数据进行区分。例子如下:
select current_value from sys.sequences where name = 'Weight_Num'
declare @seqNum bigint
select @seqNum=next value for Weight_Num
print @seqNum
457
1746

被折叠的 条评论
为什么被折叠?