I need to generate unique code like below in SQL Server
8E9560C,
2CAF902,
ADE4A86,
DF6A69E,
8074D34,
Anyone have idea how can I achieve it?
I need to generate unique code like below in SQL Server
8E9560C,
2CAF902,
ADE4A86,
DF6A69E,
8074D34,
Anyone have idea how can I achieve it?
Have you tried this ?
select newid()
or if you want only 7 chars :
select left(newid(),7)
NEWID() produces a v4 GUID. In that GUID scheme, the first 8 bytes can be any hexadecimal digit 0-F and will be composed entirely of randomly-generated data. That's not guaranteed to be unique; in fact no v4 GUID is guaranteed to be unique, it's just that the random bits (112 of 128) can represent one of 5.19 decillion numbers, so the odds of any two of them matching in the same system is infinitesimal. With only the first 8 bytes, you'll only have 2^32 combinations, which may still seem like a lot (1 in 4 billion) but by the birthday problem, after a scant 77,000 have been generated you have a 50-50 shot at generating a duplicate.