|
Re: Create table with auto increment column - HELP [message #371352 is a reply to message #371350] |
Fri, 06 October 2000 02:43 |
Prem
Messages: 79 Registered: August 1998
|
Member |
|
|
Martin,
If i got your question right, you want to create a table having a column which increments its value when records are inserted into it. Something like Autonumber?
You'll have to use database trigger then. Nothing to do with table. The table creation syntax remains the same.
Example.
Create table auto_test (id number, name varchar2(100));
create sequence seq_auto_test start with 1;
create or replace trigger trg_auto_test
before insert on auto_test
for each row
begin
select seq_auto_test.nextval into :new.id
from dual;
end;
/
now if you issue an insert like
Insert into auto_test (name) values ('Hello1');
Insert into auto_test (name) values ('Hello2');
Insert into auto_test (name) values ('Hello3');
Insert into auto_test (name) values ('Hello4');
Select * from auto_test;
it should show 1, 2, 3, 4 for the 4 rows resp.
hth
Prem :)
|
|
|
|