Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generating Primary Keys in SQL Server
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
00414202
Message ID:
00415541
Vues:
20
>>I use surrogate primary keys in VFP also. Identity column are just an easy way to auto number the next row inserted. But they do present a few problems as does just about any way that you try to id the next row.
>>
>>The old standby method of keeping a table of next ids has its problems also, i.e., you get the last number, add one to it, just as someone inserts a row and a new number before I save mine.
>>
>>The difficult part of identity columns, and I haven't come up with a satisfactory method, is when their used as foreign keys and they must be updated at the same time as the parent. As in invoice header and invoice details. You would want to handle it all in a transaction, updating the invoice header then the details.
>>
>>Maybe Michael Levy can give us an elegant way.
>
>I had a reply in the VFP Forum from Trey Walpole who suggested using GUIDs - Globally Unique Identifiers. I have read they are good for distributed and replicated data. He gave me a link to a MS page some code to generate GUIDs with VFP. This seems like a good idea, but I am concerned about performance:
>
>1. Time to generate a GUID
>2. GUID are 16 bytes, I believe

As Bob said, the call to generate a GUID is a WinAPI call so it will be very quick. And the fact that it is 16 bytes shouldn't worry you. After all, it a 16 byte integer and integers make the fastest keys.

Having said that, I use the other way. I have a table of keys but I use a stored procedure to return the next PK. The SP applies the appropriate transaction locking so duplicates are not a problem.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform