Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Auto Increment Primary key?-Q2

Re: Auto Increment Primary key?-Q2

From: John Shaft <shaft_at_meanmutha.com>
Date: Fri, 17 Dec 1999 21:04:14 -0600
Message-ID: <Pine.LNX.4.10.9912172103260.30070-100000@alfred.laffeycomputer.com>


In response to my question about how to increment a Primary key with each new INSERT so that I get an automatic unique value:

On Fri, 17 Dec 1999, Steve McDaniels wrote:

> 1. create a sequence
> 2. create table
> 3. create trigger for insert on this table
> which uses the sequence's nextval to
> populate your primary key field.

If I'm looking for a way to do this that is more portable. Sequences are not real portable, right? (to other RDBMS)

Would it be possible to achieve my end like this:

Creating another table to hold the latest primary key value Use a Transaction to select the current value and then insert the new data with the incremented value (and update the key value table). Finally, commit this as one atomic operation.

Does that sound reasonable?

Any thoughts? I am after portability over pure efficiency. I am used to dealing with MySQL, which is not as full-featured as Oracle (but is fast as hell and reall cheap). MySQL has an AUTO_INCREMENT feature that can be assigned to a column. It probably has this because it lacks transactions and sequences.

Thanks,

shaft_at_meanmutha.com
http://www.meanmutha.com Received on Fri Dec 17 1999 - 21:04:14 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US