Multiple inserts into a single table

UDA
N/A

Multiple inserts into a single table

Please Help me.

I have one table eg. Cust(cols are a, b,c,d,e) which is sourced from table Cust_add(cols used in cust are a, c) and Cust_info(cols used in cust are b,d,e)

can i do the following inserts

Insert into cust
(a
,c)
select
a
,c
from Cust_add
;Insert into cust
(b
,d
,e)
select
b
,d
,e
from Cust_info
;

3 REPLIES

Re: Multiple inserts into a single table

Generally, yes you can; but it may not be what you want. Each INSERT statement will insert new rows into your table CUST. Any column in CUST for which you do not provide a value will be set to null. As long as that column is *allowed* to be null, the insert operations will work.

In other words, if CUST_ADD has 10 rows and CUST_INFO has 5 rows, your new CUST table will have 15 rows. Columns b, d, and e will be null on the first 10 rows and columns a and c will be null on the last 5 rows.

I'll let someone else talk about the lack of an index column, if necessary.
N/A

Re: Multiple inserts into a single table



And what if I have one table eg. Cust(cols are a, b,c,d,e) which is sourced from table Cust_add(cols used in cust are a, b,c) and Cust_info(cols used in cust are b,d,e).

Here 'b' will be sourced from both tables...then will this work or give an error? What will be the result?

can i do the following inserts

Insert into cust
(a
,b
,c)
select
a
,c
from Cust_add
;Insert into cust
(b
,d
,e)
select
b
,d
,e
from Cust_info
;

N/A

Re: Multiple inserts into a single table


And what if I have one table eg. Cust(cols are a, b,c,d,e) which is sourced from table Cust_add(cols used in cust are a, b,c) and Cust_info(cols used in cust are b,d,e).

Here 'b' will be sourced from both tables...then will this work or give an error? What will be the result?
Consider b as Primary Index
can i do the following inserts

Insert into cust
(a
,b
,c)
select
a
,b
,c
from Cust_add
;Insert into cust
(b
,d
,e)
select
b
,d
,e
from Cust_info
;