| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: oracle sequence numbers
Bob Hairgrove wrote:
> On Tue, 14 Jan 2003 23:33:11 +0000, helen_fearman
> <member22597_at_dbforums.com> wrote:
>
>>What are the main pros and cons of using oracle sequence numbers for >>primary keys in situations where good unique candidate keys exist and >>which could be designated as primary keys? Is there an accepted "best >>practice"?
I thought I'd add a word of caution and expand on the suggestion of using surrogate keys only as a "last resort".
I would not recommend using a timestamp as a surrogate key. Just think about what happens when you want to insert two rows within the same second (or whatever the smallest grain of time is for your DBMS (or even your own homegrown time datatype for that matter)).
Desirable qualities for primary keys (beyond the requirements placed on all candidate keys) include:
If you've got a candidate key with these desirable qualities, then, by all means, use it as a primary key. Otherwise, a surrogate key may be used for the sake of simplicity or stability. By definition, a surrogate key will not be familiar to anyone. So surrogate keys do not help with the familiarity quality. (Though if the pre-existing candidate keys are not already familiar to people, then surrogate keys don't hurt either.)
Finally, whatever gains you expect in simplicity and stability should be weighed against the added complexity that comes with introducing a surrogate key. You've added another column. You've probably introduced a new sequence generator of some kind. You've probably got a little more code to write for inserting rows. Etc.
+Joel Received on Thu Jan 16 2003 - 01:14:21 CST
![]() |
![]() |