sql: DELETE + INSERT vs UPDATE + INSERT

后端 未结 7 1745
花落未央
花落未央 2021-01-19 02:29

A similar question has been asked, but since it always depends, I\'m asking for my specific situation separately.

I have a web-site page that shows some data that co

7条回答
  •  死守一世寂寞
    2021-01-19 03:05

    Although I fully agree with SQLMenace's answer I do would like to point out that MERGE does NOT remove unneeded records ! If you're sure that your new data will be a super-set of the existing data, then MERGE is great, otherwise you'll either need to make sure that you delete any superfluous records later on, or use the TRUNCATE + INSERT method ... (Personally I'm still a fan of the latter as it usually is quite fast, just make sure to drop all indexes/unique constraints upfront and rebuild them one by one. This has the benefit of the INSERT transaction being smaller and the index-adding being done in (smaller) transactions again later on). (**)

    (**: yes, this might be tricky on live system, but then again he already mentioned this was done during some kind of overnight anyway, I'm extrapolating there is no user-access at that time)

提交回复
热议问题