Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL版产生重复ID #94

Open
ap0405140 opened this issue Feb 7, 2024 · 1 comment
Open

SQL版产生重复ID #94

ap0405140 opened this issue Feb 7, 2024 · 1 comment

Comments

@ap0405140
Copy link

https://github.com/yitter/IdGenerator/blob/master/SQL/sqlserver.sql 的脚本创建函数, 测试产生有重复ID.
测试脚本如下:

-- 建测试表,并产生1000个ID
if object_id('tempdb..#r') is not null
drop table #r

create table #r
(
rn int identity(1,1) not null,
id bigint not null
)

set nocount on
declare @A int,@b int
select @A=1,@b=1000
while(@A<=@b)
begin
insert into #r(id)
select id=dbo.Fn_NextSnowId(rand())
select @A=@A+1
end
set nocount off

-- 结果有重复
select id,count(1)
from #r
group by id
having count(1)>1

@yitter
Copy link
Owner

yitter commented Feb 12, 2024

SQL版本理论上会产生重复数,不要用于高并发生产环境

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants