-- 建测试表,并产生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
按 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