[EMAIL PROTECTED] wrote:
 
> I'm new to this db and have one problem.
> 
> I have 2 tables:
> Table1(T1ID - PK, ...) 
> Table2(T2ID - PK, T1ID - FK,... )
> 
> How can I insert data into both tables at once 
> or at least can I know PK (if it is autoincrement) after insert?
> 
> Now I have to do this:
> Insert into Table1(...) values (...)
> Select T1ID from Table1 where ...
> Insert Table2(T1ID,...) values (T!ID,...)

As discussed several times in this list
(see http://listserv.sap.com/search/search.sapdb.general.html )

create sequence myseq

insert into table1 (..) values (myseq.nextval, ...)
insert into table2 (..) values (myseq.currval,...)

if you use serial in table1, the you will not be able to use currval
and selecting may result in the 'wrong' number if in multi-user-environment
another guy has inserted a row which may fulfil your qualification.

Elke
SAP Labs Berlin
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general

Reply via email to