Re: automatic unique key genration

From: Randy Dewoolfson <randyd_at_cais3.cais.com>
Date: 1995/12/07
Message-ID: <4a5jdl$5vp_at_zippy.cais.net>#1/1


DANGER!
The rowid is not guaranteed to be unique across EXPORT IMPORT or other table defragmentation schemes (most use exp / imp).

The short story here is DON'T REINVENT THE SEQUENCE.

EndUser (enduser_at_enduser.com) wrote:
: to use max(cn)+1 you need t lock the table, get the value,
: or insert the row, then go on.
 

: to get a unique key which does not depend on a sequence, but is
: unique is to use the ROWID of the just inserted row, you should
: also lock tables/rows to insure your work.
 

: --
 

: In article <49hr6b$d2o_at_lyra.csx.cam.ac.uk>, Charles Jardine
: <cj10_at_cam.ac.uk> wrote:
 

: > Ramesh K Meda <74053.36_at_CompuServe.COM> wrote:
: > >Yes, unique key could be generated for primary key. There are two
: > >different ways.
: > >
: > >1. Use sequence and set value for new.<column_name>.
: > >2. Use max(PrimaryColumnName) + 1 to set new value.
: > >
: > >Depending on the platform and oracle release you might be using,
: > >you may receive "Mutating" error. Hope, you know how to solve
: > >this.
: >
: > Solution 2 above is simply wrong, first because of the mutating
: > problem and secondly because two concurrent transactions may well
: > see the same value of max(PrimaryColumnName) + 1. Any way of cheating
: > to get round there restriction on selecting from mutating tables
: > will make the second effect more likely.
: >
: > The whole point of sequences is that they are outside the transaction
: > structure, and can deliver guaranteed uniquness without blocking locks.
: > The only cost is that sequence numbers can be 'lost' because NEXTVALs
: > given to transaction which roll back are never given to anyone else.

--
    ..uu.                                     ----------------------
  .?$" '?i     .                              I  Randy DeWoolfson  I
 .T^M  ._at_"    d9    .     f   ,.un.  b,    i  I--------------------I
 "  Z :#"    M `8   U    <  .dP"``"# `M   _at_"  I  randyd_at_cais.com   I
    &H?`    Xl _R   $5.  $  ?*    _at_   'P,#"   I--------------------I
  ,d#^*L   :RP'~$b  f`$L:M  Xf  .f'    dH`    I        ,\//.       I
    &  'M ,P    `E  M   "$  Mux~      n!`     I        |o o|       I
   dk   `h"       ' j     " y"       *~       I====oOO==(_)==Ooo===I
Received on Thu Dec 07 1995 - 00:00:00 CET

Original text of this message