简体   繁体   中英

In oracle database how do we maintain same surrogate key (sequence value) on both tables simultaneously

In our data warehouse, we have a requirement to load 2 tables which are at the same grain. Volume in both tables is exactly same. During the insert, i need to load same surrogate key (sequence) simultaneously. Are there any ways to achieve this?

There are too many unknowns about your ETL process, so I apologize if this is way off. It's too long for a comment though.

You can insert into multiple tables at the same time using the INSERT ALL command. Like this:

create sequence matt_s;
create table etl1 ( id number, other_data VARCHAR2(30));
create table etl2 ( id number, other_data VARCHAR2(30));

insert all 
  into etl1 (id, other_data) values ( matt_s.nextval, other_data )
  into etl2 (id, other_data) values ( matt_s.nextval, other_data )
select /* dummy source data */ 
       to_char(rownum) other_data
from   dual src
connect by rownum <= 50;

Every row in the source query will be inserted into both tables and share common values for the id column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM