473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Using GUID Autonumers pros and cons

So far, I have never chosen to use GUIDs as Autonumer keys for the tables in
my projects, but a recent experience has got me to wondering.

I have recently been working on a system that, during the early testing
phases, has a fairly extensive schema, fairly few records, and quite a bit of
UI code to handle things that don't work well via bound forms.

In this application, I have repeatedly had bugs initially go undetected
involving the use of the wrong field because it just happened to have a value
of something like 1 or 2 that just happened to be the right value in the
testing context. It seems to me that this situation could be greatly improved
by using GUIDs, and I'm wondering what the experience of others here has been
regarding the use of Longs vs GUIDs.

As I'm typing this, I realize there's another option that would help which is
using Random rather than Increment for the New Values argument (a less redical
option?), so I guess the question is - Increment, Random, or Replication ID.

Opinions?
Nov 13 '05 #1
8 2395
Steve Jorgensen <no****@nospam.nospam> wrote in
news:16********************************@4ax.com:
So far, I have never chosen to use GUIDs as Autonumer keys for the
tables in my projects, but a recent experience has got me to
wondering.
Don't:

http://trigeminal.com/usenet/usenet011.asp?1033

That specifically considers the use of GUIDs in replication (about
the only place where it theoretically makes sense), but all but one
of the pitfalls MichKa describes (#1) apply to non-replicated apps.
I have recently been working on a system that, during the early
testing phases, has a fairly extensive schema, fairly few records,
and quite a bit of UI code to handle things that don't work well
via bound forms.

In this application, I have repeatedly had bugs initially go
undetected involving the use of the wrong field because it just
happened to have a value of something like 1 or 2 that just
happened to be the right value in the testing context. It seems
to me that this situation could be greatly improved by using
GUIDs, and I'm wondering what the experience of others here has
been regarding the use of Longs vs GUIDs.
VBA vs. ADO vs. DAO -- all three handle them differently.
As I'm typing this, I realize there's another option that would
help which is using Random rather than Increment for the New
Values argument (a less redical option?), so I guess the question
is - Increment, Random, or Replication ID.


Don't use ReplicationID in a non-replicated context. Even in a
replicated app, don't use them, because of MichKa's warnings.

As to random, I don't quite see why it matters if they are random or
not. Random AutoNumbers seem to me to have only two uses:

1. in a replicated app insures that the chances of PK collision
between replicas is minuscule (I've never seen a collision).

2. distributes the values in a PK index uniformly over the entire
range of possible values and not sequentially. This could
conceivably be a performance enhancer, as new values will not all be
on the same index data page.

But GUIDs are not usable.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #2
> 1. in a replicated app insures that the chances of PK collision
between replicas is minuscule (I've never seen a collision).
If you're working with small enough datasets to fit into memory, you
can generate random numbers yourself, without needing to be connected
to the database. ( Can be very useful for sales support. ) You can
also generate negative sequential numbers and then let the db reassign
them, but this can be difficult with lots of relational tables.
2. distributes the values in a PK index uniformly over the entire
range of possible values and not sequentially. This could
conceivably be a performance enhancer, as new values will not all be
on the same index data page.
Interesting - I didn't think of that. They can be either useful for
security or a huge pain in the butt, in that they hide the order you
put records into your tables.
But GUIDs are not usable.


Totally agree.
Nov 13 '05 #3
On Thu, 18 Nov 2004 17:24:59 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
Steve Jorgensen <no****@nospam.nospam> wrote in
news:16********************************@4ax.com :
So far, I have never chosen to use GUIDs as Autonumer keys for the
tables in my projects, but a recent experience has got me to
wondering.
Don't:

http://trigeminal.com/usenet/usenet011.asp?1033


Very convincing - I'm convinced. It sounds like the idea is that you never
want to use GUIDs except for the unusual cases in which you still never want
to use GUIDs <g>, though Access may use them for you with replication, right?

...
In this application, I have repeatedly had bugs initially go
undetected involving the use of the wrong field because it just
happened to have a value of something like 1 or 2 that just
happened to be the right value in the testing context. It seems
to me that this situation could be greatly improved by using
GUIDs, and I'm wondering what the experience of others here has
been regarding the use of Longs vs GUIDs.


VBA vs. ADO vs. DAO -- all three handle them differently.
As I'm typing this, I realize there's another option that would
help which is using Random rather than Increment for the New
Values argument (a less redical option?), so I guess the question
is - Increment, Random, or Replication ID.

....
As to random, I don't quite see why it matters if they are random or
not. Random AutoNumbers seem to me to have only two uses:

1. in a replicated app insures that the chances of PK collision
between replicas is minuscule (I've never seen a collision).

2. distributes the values in a PK index uniformly over the entire
range of possible values and not sequentially. This could
conceivably be a performance enhancer, as new values will not all be
on the same index data page.

But GUIDs are not usable.


Well, it matters for the reason I stated. I want the code to break the first
time I try to use a value from the same column, not accidentally work in early
testing because the id value happens to be something like 1 or 2, then fail
later when it's harder to track down. It seems like random Autoincrments
would be a big help for that.
Nov 13 '05 #4
On Fri, 19 Nov 2004 04:32:43 GMT, Steve Jorgensen
<no****@nospam.nospam> wrote:

Well, it matters for the reason I stated. I want the code to break the first
time I try to use a value from the same column, not accidentally work in early
testing because the id value happens to be something like 1 or 2, then fail
later when it's harder to track down. It seems like random Autoincrments
would be a big help for that.


Hi
I'm sure that random autonumbers are exactly what you want in the
present case, but in some cases the idea of unique ids is very
appealling. The easiest way is to use the components of a GUID-like
object as separate fields. The 1996 spec for guids is explained here:
http://kruithof.xs4all.nl/guid-uuid-info.html
David

Nov 13 '05 #5
I made a confusing typo there. "the first time I try to use a value from the
same column" should say "the first time I try to use a value from the wrong
column".

On Fri, 19 Nov 2004 04:32:43 GMT, Steve Jorgensen <no****@nospam.nospam>
wrote:
On Thu, 18 Nov 2004 17:24:59 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
Steve Jorgensen <no****@nospam.nospam> wrote in
news:16********************************@4ax.co m:
So far, I have never chosen to use GUIDs as Autonumer keys for the
tables in my projects, but a recent experience has got me to
wondering.


Don't:

http://trigeminal.com/usenet/usenet011.asp?1033


Very convincing - I'm convinced. It sounds like the idea is that you never
want to use GUIDs except for the unusual cases in which you still never want
to use GUIDs <g>, though Access may use them for you with replication, right?

..
In this application, I have repeatedly had bugs initially go
undetected involving the use of the wrong field because it just
happened to have a value of something like 1 or 2 that just
happened to be the right value in the testing context. It seems
to me that this situation could be greatly improved by using
GUIDs, and I'm wondering what the experience of others here has
been regarding the use of Longs vs GUIDs.


VBA vs. ADO vs. DAO -- all three handle them differently.
As I'm typing this, I realize there's another option that would
help which is using Random rather than Increment for the New
Values argument (a less redical option?), so I guess the question
is - Increment, Random, or Replication ID.

...

As to random, I don't quite see why it matters if they are random or
not. Random AutoNumbers seem to me to have only two uses:

1. in a replicated app insures that the chances of PK collision
between replicas is minuscule (I've never seen a collision).

2. distributes the values in a PK index uniformly over the entire
range of possible values and not sequentially. This could
conceivably be a performance enhancer, as new values will not all be
on the same index data page.

But GUIDs are not usable.


Well, it matters for the reason I stated. I want the code to break the first
time I try to use a value from the same column, not accidentally work in early
testing because the id value happens to be something like 1 or 2, then fail
later when it's harder to track down. It seems like random Autoincrments
would be a big help for that.


Nov 13 '05 #6
On 19 Nov 2004 03:48:14 -0600, d.***************@blueyonder.co.uk (David
Schofield) wrote:
On Fri, 19 Nov 2004 04:32:43 GMT, Steve Jorgensen
<no****@nospam.nospam> wrote:

Well, it matters for the reason I stated. I want the code to break the first
time I try to use a value from the same column, not accidentally work in early
testing because the id value happens to be something like 1 or 2, then fail
later when it's harder to track down. It seems like random Autoincrments
would be a big help for that.


Hi
I'm sure that random autonumbers are exactly what you want in the
present case, but in some cases the idea of unique ids is very
appealling. The easiest way is to use the components of a GUID-like
object as separate fields. The 1996 spec for guids is explained here:
http://kruithof.xs4all.nl/guid-uuid-info.html
David


Thanks, I do get the distinction between the use of a GUID/UUID for
application purposes and the use of a GUID-typed field in a table. I've been
hoping to use UUIDs to identify entities across separate component
applications at some point, such as holding a reference to a Party entity in a
business application that was obtained from a separate contact management
application.
Nov 13 '05 #7
Va************@gmail.com (Forrest) wrote in
news:9d**************************@posting.google.c om:
1. in a replicated app insures that the chances of PK collision
between replicas is minuscule (I've never seen a collision).


If you're working with small enough datasets to fit into memory,
you can generate random numbers yourself, without needing to be
connected to the database. ( Can be very useful for sales
support. ) You can also generate negative sequential numbers and
then let the db reassign them, but this can be difficult with lots
of relational tables.


Such a method will be computationally more intensive than relying on
Jet's random AutoNumber because you're homegrown method will have to
check if the value already exists, whereas that's built into the Jet
random AutoNumber functionality.

And exactly what random number generator will you use? The VBA one?
2. distributes the values in a PK index uniformly over the entire
range of possible values and not sequentially. This could
conceivably be a performance enhancer, as new values will not all
be on the same index data page.


Interesting - I didn't think of that. They can be either useful
for security or a huge pain in the butt, in that they hide the
order you put records into your tables.


If it's the PK, they shouldn't have any meaning at all.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8
Steve Jorgensen <no****@nospam.nospam> wrote in
news:i5********************************@4ax.com:
On Thu, 18 Nov 2004 17:24:59 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
Steve Jorgensen <no****@nospam.nospam> wrote in
news:16********************************@4ax.co m:
So far, I have never chosen to use GUIDs as Autonumer keys for
the tables in my projects, but a recent experience has got me to
wondering.


Don't:

http://trigeminal.com/usenet/usenet011.asp?1033


Very convincing - I'm convinced. It sounds like the idea is that
you never want to use GUIDs except for the unusual cases in which
you still never want to use GUIDs <g>, though Access may use them
for you with replication, right?


Jet uses them behind the scenes for identifying replication objects.
But it never gets to the UI level and you never have to deal with
tme in code.

Though I guess you could if you *wanted* to -- but I can't think of
a reason why you'd want to, except if you had a case where
replication had been broken and you had to do the synchronization
"manually." I've done it, actually, but I didn't write any code for
GUIDs. I did use them as criteria in queries (in place of joins
between GUID fields, which are not supported in the QBE UI; dunno if
they are supported in Jet SQL, though -- never tried it).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sniffle | last post by:
Thanks... Say you have a double opt in mailing list, of which the subcriber list is store in the db. Im still somewhat of a newb, so bear with me... are there any pros/cons as to keeping the...
0
by: Steve | last post by:
We've recently got a new Server in. The server has 16Gb of RAM, 8 cpus etc We now have a choice of sticking with Windows 2000 Advanced Server or going with Windows 2003 Enterprise edition. ...
112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
5
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating...
50
by: Steve | last post by:
How do you rewrite the swap function without using a tmp variable in the swap function???? int main() { int x = 3; int y = 5; // Passing by reference
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
7
by: zahy[dot]bnaya[At]gmail[dot]com | last post by:
Hi all, Since I am always confusing this, I want to know once and for all what is the right way of doing this. I've noticed that some programs use: std::cout<< "yadayada"<<endl;
18
by: Angus | last post by:
Hello We have a lot of C++ code. And we need to now create a library which can be used from C and C++. Given that we have a lot of C++ code using classes how can we 'hide' the fact that it is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.