Forum INFOMATH
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
-20%
Le deal à ne pas rater :
Drone Dji DJI Mini 4K (EU)
239 € 299 €
Voir le deal

Advantages and disadvantages of GUID / UUID database keys

Aller en bas

Advantages and disadvantages of GUID / UUID database keys Empty Advantages and disadvantages of GUID / UUID database keys

Message par Napoléon Mar 30 Aoû - 0:33


http://stackoverflow.com/questions/45399/advantages-and-disadvantages-of-guid-uuid-database-keys

The Question:

I've worked on a number of database systems in the past where moving entries between databases would have been made a lot easier if all the database keys had been GUID / UUID values. I've considered going down this path a few times, but there's always a bit of uncertainty, especially around performance and un-read-out-over-the-phone-able URLs.

Has anyone worked extensively with GUIDs in a database? What advantages would I get by going that way, and what are the likely pitfalls?

The answer:

Advantages:

Can generate them offline.
Makes replication trivial (as opposed to int's, which makes is REALLY hard)
ORM's usually like them
unique accross applications. So We can use the PK's from our CMS (guid) in our app (also guid) and know we are NEVER going to get a clash.

Disadvantages:

Larger space use, but space is cheap(er)
can't order by ID to get the insert order.
Can look ugly in a URL, but really, WTF are you doing putting a REAL DB key in a URL!?
Harder to do manual debugging, but not that hard

Personally, I use them for most PK's in any system of a decent size, but I got "trained" on a system which was replicated all over the place, so we HAD to have them. YMMV.

I think the duplicate data thing is rubbish - you can get duplicate data however you do it. Surrogate keys are usually frowned upon whereever I've been working. We DO use the wordpress-like system tho:

unique ID for the row (GUID/whatever). Never visible to the user.
public ID is generated ONCE from some field (eg the title - make it the-title-of-the-article)

Works for us Smile

Napoléon
Napoléon
Admin
Admin

Masculin
Nombre de messages : 2934
Localisation : Tunisie
Réputation : 122
Points : 7872
Date d'inscription : 19/03/2007

Feuille de personnage
Capacité linguistique:
Advantages and disadvantages of GUID / UUID database keys Left_bar_bleue999/1000Advantages and disadvantages of GUID / UUID database keys Empty_bar_bleue  (999/1000)

https://infomath.1fr1.net

Revenir en haut Aller en bas

Advantages and disadvantages of GUID / UUID database keys Empty Re: Advantages and disadvantages of GUID / UUID database keys

Message par Napoléon Mar 30 Aoû - 0:39

See also:

http://www.codinghorror.com/blog/2007/03/primary-keys-ids-versus-guids.html
Napoléon
Napoléon
Admin
Admin

Masculin
Nombre de messages : 2934
Localisation : Tunisie
Réputation : 122
Points : 7872
Date d'inscription : 19/03/2007

Feuille de personnage
Capacité linguistique:
Advantages and disadvantages of GUID / UUID database keys Left_bar_bleue999/1000Advantages and disadvantages of GUID / UUID database keys Empty_bar_bleue  (999/1000)

https://infomath.1fr1.net

Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum