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: How Can I Create a Table Which will has a AUTO ID Field ?

Re: How Can I Create a Table Which will has a AUTO ID Field ?

From: Ludovic DESSEMON <Pepiniere.rey_at_wanadoo.fr>
Date: 29 Apr 1998 09:35:31 GMT
Message-ID: <01bd7351$ed7a4380$0b0000c0@ludovic>

SEED <jasonch_at_ms1.hinet.net> a écrit dans l'article <6hp06j$kb7_at_news.seed.net.tw>...
> Hi! Everybody
> This mail was from Taiwan. I had a question as Titile above.It's
> important for me to create a table with a AUTO ID Field , that means no
> matter when I insert or append a record , the database system will assist
me
> to write a sequential number to that AUTO ID field. I'd been a user of MS
> SQL SERVER , it will do that kind function for me, Can Oracle do that ?
> Is there any one can assist me to solve such a problem ? mail me
> ,please! My mail was
> jasonch_at_ms1.hinet.net or
> 1596_at_cpc.org.tw
>
>
>
>

You can use the triggers :

create trigger my_trigger
before insert on my_table
for each row
begin

   select max(id)+1 into :new.id

      from my_table;
end;

OR

You have the possibility to create a sequence.

Under Oracle:
Create sequence seq_my_table increment by 1 start with 0 maxvalue 99999 minvalue 0;

In your application :
Insert into my_table (id, nickname, age) values (seq_my_table.NEXTVAL, 'scott', 20);

Ludovic Received on Wed Apr 29 1998 - 04:35:31 CDT

Original text of this message

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