ANSI SQL has something called sequence generators.
[tt]
create sequence s no cycle;
create table t (id integer default next value for s, c1 character(10));
[/tt]
Works fine when inserting one row at the time:[tt]
SQL>insert into t (c1) values ('1:st');
SQL>insert into t (c1) values ('2:nd');
SQL>select * from t;
ID C1
=========== ==========
1 1:st
2 2:nd
[/tt]
But does not work when inserting several rows with one insert:[tt]
insert into t(c1) select somecolumn from sometable;
[/tt]
In this case the id column will have the same value for all inserted rows. (The "next value for s" is only performed once for a statement.)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.