Les GUIDs... bien ou pas?

A

AW

Bonjour,

Après avoir parcouru des dizaines de pages sur les GUIDs, je ne suis
toujours pas fixé.

Mon but est d'avoir un comportement similaire entre SQL Server et Oracle
lors de l'insertion de lignes, et le problème se pose pour récupérer la clé
primaire d'une ligne insérée. Je peux utiliser une IDENTITY de SQL Server
pour autogénérer la clé, puis faire un SELECT @@IDENTITY, mais Oracle ne
connaît pas. Du coup pour Oracle je dois utiliser un trigger puis un SELECT
MAX. Ce n'est pas du tout la même manière de faire.

L'idée est donc de générer moi-même (en .net c'est facile) un GUID avec le
programme, qui sera utilisé comme clé primaire de la ligne insérée. En
théorie ça marche, mais apparemment ça risque de poser des problèmes de
performance.

Quelqu'un a-t-il un retour d'expérience? Je compte ainsi transformer les
clés primaires de TOUTES mes tables en GUIDs. Il s'agit d'une appli
professionnelle, donc avec beaucoup de tables et d'entrées.

Merci pour vos avis.
 
B

bruno reiter [MVP]

Pour avoir un comportement similaire, je pense qu'il vaut mieux utiliser un
trigger avec un champ de type int.
par trigger tu modifies pour prendre la 1ere valeur dispo.

br
 
A

AW

Hi all,

Sorry for my previous post in French, I mistakenly posted it here without
translation.

So, the problem: after reading tens of pages about GUIDs, I still don't know
what to do.

I would like to get the same behaviour with SQL Server and Oracle when
inserting lines. The problem comes when I try to get the primary ID value of
a newly inserted line. I can use the IDENTITY type of SQL Server to
automatically generate the key, and then get it through a SELECT @@IDENTITY,
but Oracle doesn't handle this. So with Oracle I have to use a trigger and
the SELECT MAX, but then it's not the same way to do.

So the idea is to generate a GUID myself (easy using the .net framework),
that way I will know the ID of the inserted line. Theorically this seems
good, but there may be concerns with performance.

Does anybody know how GUIDs perform in real life with SQL Server? I intend
to use them for the primary keys of each table in my database. This is for a
professionnal application, with many tables and rows.

Thanks for any help.
 
M

Miha Markic

Hi AW,

I would prefer numeric PKs.
The main reason would be that they are way easier to read for humans and
programers :)
They are also faster to retrieve from db and other operations (int is 4
bytes while guid is 16 bytes).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top