Forum Stats

  • 3,838,564 Users
  • 2,262,383 Discussions
  • 7,900,687 Comments

Discussions

Merge or other?

User_2TTDA
User_2TTDA Member Posts: 2 Green Ribbon

I have a table with more than 300 million rows, and it is not possible to run the base at once. How to update/include this database?

Today for smaller bases I use the merge that allows me to update/update


MERGE INTO FATURA_ASSINANTE USING AJUSTE_FATURA ON FATURA_ASSINANTE.COD_ASSINANTE=AJUSTE_FATURA.COD_ASSINANTE
WHEN NOT MATCHED THEN INSERT VALUES AJUSTE_FATURA.COD_ASSINANTE, AJUSTE_FATURA.COD_PLANO
WHEN 	 MATCHED THEN UPDATE SET FATURA_ASSINANTE.VALOR_FATURADO = AJUSTE_FATURA.NOVO_VALOR 
Tagged:

Answers

  • Solomon Yakobson
    Solomon Yakobson Member Posts: 19,594 Red Diamond

    You need to tell us both table row counts. So table FATURA_ASSINANTE has 300 million rows. What about AJUSTE_FATURA? WHat indexes do you have? And how many of AJUSTE_FATURA matching rows have VALOR_FATURADO different from value in table FATURA_ASSINANTE (in other word would adding WHERE clause to WHEN match would signinficantly reduce number of updates)?

    SY.

    User_2TTDA