Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create unique ID

Status
Not open for further replies.

Zipster

Programmer
Nov 13, 2000
107
GB
Hi,

I am creating a system whereby users create there own accounts using ASP and SQL Server, I'm not a pro with SQL DB but am learning pretty quickly.

What I want to know is how to create a Unique ID, one that doesn't have a chance of getting duplicated and not incremental to the previous ID.

How do I go about creating such an ID?

Thanks in advance for any help.
 
Why the requirement for it to not be incremental? The only way your giong to get truly unique numbers is to either use an incremental field or try to build your own with double checks against the db:
Building Your Own:
Random Numbers:
1) Create a random number between 1 and 1,000,000
(this will give us 6 digits, increasing this number decreases the chance of a non-unique ID on first try)
2) Check it with the db to make sure it doesn't already exist
3) loop until you have a valid unique id

Date Time:
a function on the date and time, ie right now the id could be something based on 200212051354 (YYYYMMDDhhmm)
if you don't mind strings, how about: 2E9D91759A (Hex)
or using 2 digit year:
0212051354 =%gt; CA3A59A (hex)


Anyways, just some thoughts.

-Tarwn
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Some more examples for the date/time unique ID now that I finished writing a decimal to n-ary convertor:
Code:
Base Converted Value
----|---------------------------------------------
10: | 20021205145639  <- original value YYYYMMDDhhmmss
2:  | 100100011010110001100110100100001100000100111
4:  | 10203112030310201200213
8:  | 443261464414047
16: | 12358CD21827
27: | 2GO065IDP4
32: | I6M6D4617
Can't get much more unique than this without more work.

Give 'em the binary one and tell them they have to memorize it
devilgrin.gif


-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Setup a table that uses a GUID as the indentifier, long number I don't think it's sequential .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top