A nice way to make a unique 10 character string is to generate a GUID, strip out the hypehens, and take only the left / right 10 characters as follows:
select right(replace(CONVERT(varchar(255), NEWID()), '-',''),10)
This produces no duplicates over 1 million rows, when tested as follows:
create table #tmpID(ID varchar(10))
declare @i int
set @i = 1
while @i <1000000
begin
insert into #tmpID
select right(replace(CONVERT(varchar(255), NEWID()), '-',''),10)
set @i = @i+1
end
select ID, count(*) [No of IDs]
from #tmpID
group by ID
having count(*) >1
No comments:
Post a Comment