Sql NEWID()

Status
Not open for further replies.

fitten

Ars Legatus Legionis
55,634
Subscriptor++
If you were to store every GUID as a string for your list, you'd need ~1000 billion billion billion gigabytes of storage.

If you want to know if something is a valid GUID, you can use a regex. Or you can try to convert/cast the string to a GUID (uniqueid) and if it fails, it's not one.

Edit (friend told me): Or, if you want a list, you can shorten your list by saying "every possible value from 00000000-0000-0000-0000-000000000000 to FFFFFFFF-FFFF-FFFF-FFFFFFFFFFFF, inclusive".
 

Dracorat

Ars Tribunus Militum
2,798
That would actually never generate all of them. The algorithm used generally includes something specific to the machine (like a MAC address) in its generation code. You'd get eventually all the possible values for that specific computer but not all possible values. The only way to do that would be to use a RAW (or binary) field, start at 0 and loop with +1 until you get to Fx32
 

fitten

Ars Legatus Legionis
55,634
Subscriptor++
Yup, and even then... even if you can generate 2^^32 per second (for a nice round number), you're still looking at around 2^^71 years to complete the task (a year is almost 2^^25 seconds). 2^^(128-32-25)

Anyway, we've picked this apart too much. Without more information from the OP to know what he's actually trying to do, we're just stabbing in the dark.

I'm guessing the OP wants to be able to validate that something passed in is, in fact, a GUID. A column can be declared 'uniqueidentifier' and nothing that can't be converted successfully will be allowed to be inserted.

Alternately,
Code:
@"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$"

is a regex for matching GUIDs.
 
Status
Not open for further replies.