34,593
社区成员
发帖
与我相关
我的任务
分享
-- 建测试表
create table #t(c varchar(50))
create index ix_#t on #t(c)
-- 产生10000个不重复的16位随机数.
set nocount on
declare @x int,@t varchar(50),@r float
select @x=1
while(@x<=10000)
begin
select @r=rand()
select @r=case when @r>0.1 then @r else @r+0.1 end
select @t=rtrim(cast(@r*10000000000000000 as bigint))
if not exists(select 1 from #t where c=@t)
begin
insert into #t(c) values(@t)
select @x=@x+1
end
end
set nocount off
-- 结果
-- 1 长度统计
select len(c) 'length',
count(1) 'qty'
from #t
group by len(c)
/*
length qty
----------- -----------
16 10000
(1 row(s) affected)
*/
-- 2 去重复统计
select count(distinct c) 'qty' from #t
/*
qty
-----------
10000
(1 row(s) affected)
*/
select cast(rand()*10000000000000000 as bigint)
select left(REPLACE(newid(),'-',''),16)
CB41550104064DC5