Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: How Can I Create a Table Which will has a AUTO ID Field ?
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
![]() |
![]() |