Skip to main content
Known Participant
May 28, 2007
Question

UUID for Primary Key?

  • May 28, 2007
  • 11 replies
  • 2167 views
The fundamental question is:
Should I use UUID for primary keys in my database tables or should I just use the typical integer that is auto-incremented with every new row?

I'm trying to understand what the trade space is.

Thanks!
This topic has been closed for replies.

11 replies

Participating Frequently
June 18, 2007
I have not tried this method, but here is a good write-up of a radical speed increase over createUUID().

http://www.firemoss.com/blog/index.cfm?mode=entry&entry=BC614E9B-3048-55C9-432594FC1E443986
Inspiring
June 17, 2007
suluclac wrote:
> Well, I just read on Camden's blog that you can only create 64 UUIDs per
> second???

On Windows that is correct. On platforms with better time resolution you
may get more.


> Well that sucks. I just overhauled my DB and application code to use uuids.
> If lots of you are indeed using this as your table primary keys, how do you
> get around this if your application needs to scale?

Either use the database to generate them or find another Java library to
generate them. And go to http://www.adobe.com/go/wish/ to make sure
Adobe fixes this.

Jochem


--
Jochem van Dieten
Adobe Community Expert for ColdFusion
Inspiring
June 17, 2007
> Well that sucks. I just overhauled my DB and application code to use uuids.
> If lots of you are indeed using this as your table primary keys, how do you
> get around this if your application needs to scale?

Get your DB to generate the UUIDs, not CF?

--
Adam
suluclacAuthor
Known Participant
June 17, 2007
Well, I just read on Camden's blog that you can only create 64 UUIDs per second???
Well that sucks. I just overhauled my DB and application code to use uuids.
If lots of you are indeed using this as your table primary keys, how do you get around this if your application needs to scale?
Inspiring
May 30, 2007
This is slightly of topic but still applicable to the discussion at hand.

If you are using Microsoft SQL Server you can use the UNIQUEIDENTIFIER data type to store Microsoft style GUIDs. The Microsoft GUID and ColdFusion's UUID only differ by the placement of dashes within the string and you can easily convert a UUID to a GUID by adding an extra dash. MS SQL server has a build in function, NEWID(), that you could also use to create GUIDs for use in your database.

I have included a link to a UDF to create GUIDs in ColdFusion below.
http://www.cflib.org/udf.cfm?ID=54
Inspiring
May 30, 2007
This is slightly of topic but still applicable to the discussion at hand.

If you are using Microsoft SQL Server you can use the UNIQUEIDENTIFIER data type to store Microsoft style GUIDs. The Microsoft GUID and ColdFusion's UUID only differ by the placement of dashes within the string and you can easily convert a UUID to a GUID by adding an extra dash. MS SQL server has a build in function, NEWID(), that you could also use to create GUIDs for use in your database.

I have included a link to a UDF to create GUIDs in ColdFusion below.
http://www.cflib.org/udf.cfm?ID=54
Inspiring
May 29, 2007
Another consideration is the number of ways you want to allow data into your db. If it's via cold fusion web pages only, then it's no big deal since cf has a function to generate your uuid's. If you are using other methods, such as bulk loading of text files, then those autoincrement integers are awfully attractive.
May 29, 2007
A lot of dbms' have an internal function to generate uuid like numbers as well. Oracle has SYS_GUID, MS sql server has NEWID(), mysql has UUID()/
Inspiring
May 29, 2007
> UUID/guid versus integer (identity or otherwise) is a piece of database
> religion. There are many who have strong opinions on both sides of the
> argument. The main argument for ints against uuids is space and a couple of
> milliseconds. The main argument for uuids against ints is that it better
> satisfies the rule that there should be no "intelligence" in your primary key
> and that you are guaranteed that your pks from various tables won't collide if
> you need to merge disparate data

This is pretty much exactly our stance on it.

--
Adam
May 29, 2007
I use the UUID when I design database for Coldfusion Application for the same reason which Mike_the_maven mentioned which is the security reason and make sure to have a unique when I publish the production Database to the backup (center) database(synch two different databases to center one)

Good luck
Mamdoh
suluclacAuthor
Known Participant
May 29, 2007
So it sounds like from a security and scalability point of view, uuid is the way to go. I suspected that might be the case, but wasn't certain.
Don't quite understand what is meant by "intelligence". I'll go do some homework.

Thank you mike!
May 29, 2007
Intelligence refers to the PK having some meaningful information encoded into it such as a date 20070528214960 or that ids from 1-1000 are for one type of product and 1001-2000 are another type or that id 8 was added after id 7 but before 9. PKs should be able to be reassigned as needed without it affecting data