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: automatically creating unqiue primary keys with triggers and sequences

Re: automatically creating unqiue primary keys with triggers and sequences

From: Mohamad SALEH <msaleh_at_orsys.fr>
Date: 2000/05/22
Message-ID: <39294EEE.826AE574@orsys.fr>#1/1

Felix von Delius a écrit :

> Hi,
>
> I'm porting an app from MySQL to Oracle 8 and ask me, if it is possible
> to use a trigger and a sequence to accomplish the same effect as MySQL's
> "autoincrement" feature.
>
> In MySQL, when you define a primary key like this:
>
> CREATE TABLE MyTab (
> id integer DEFAULT 0 NOT NULL AUTO_INCREMENT,
> name char(30),
> PRIMARY KEY(id)
> );
>
> you can easily do
>
> INSERT INTO MyTab (name) VALUES ('Felix');
>
> without generating a unique primary key.
>
> How can I emulate this with triggers and sequences so that I don't have
> to change the application?
>
> -Felix

You must use a BEFORE EACH ROW trigger that modifies the value of ":NEW.id" using the sequence

--
Mohamad
Received on Mon May 22 2000 - 00:00:00 CDT

Original text of this message

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