Re: automatic unique key genration

From: EndUser <enduser_at_enduser.com>
Date: 1995/12/01
Message-ID: <enduser-0112950729390001_at_204.247.5.26>#1/1


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.
Received on Fri Dec 01 1995 - 00:00:00 CET

Original text of this message