How to merge multiple updates into different tables?

3

I have 3 updates, and the tables I have to give the updates have 2 million records, so it would be unfeasible to do one by one, since each one takes more than half an hour to run, and wait for one to finish. running the other is not productive.

How do I unite them in a single update, or even a while / for (I tried to do this, but my SQL knowledge is limited).

Follow the updates:

update reference_bankaccount set internalid = v.internal_id 
from  contract_reference v 
where v.external_id = externalid
and internalid = ''

update reference_vendor set internalid = v.internal_id 
from  contract_reference v 
where v.external_id = externalid
and internalid = ''

update reference_customer set internalid = v.internal_id 
from  contract_reference v 
where v.external_id = externalid
and internalid = ''

I looked here in SOpt, but the guys just asked about changing several columns in the same table, not on different tables.

    
asked by anonymous 07.08.2018 / 15:42

1 answer

0

I was able to solve with the help of Reginaldo Rigo as follows:

update reference_bankaccount set internalid = v.internal_id 
from  contract_reference v 
where v.external_id = externalid
and internalid = '';

update reference_vendor set internalid = v.internal_id 
from  contract_reference v 
where v.external_id = externalid
and internalid = '';

update reference_customer set internalid = v.internal_id 
from  contract_reference v 
where v.external_id = externalid
and internalid = '';

Adding the; at the end of the updates, they run in sequence, without me expecting to finish one by to run the other. :)

    
24.09.2018 / 16:34