sql: DELETE + INSERT vs UPDATE + INSERT

后端 未结 7 1730
花落未央
花落未央 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:13

    It depends on the size of the table and the recovery model on the database. If you are deleting many hundreds of thousands of records and reinstating them vs updating a small batch of a few hundred and inserting tens of rows, it will add an unnecessary size to your transaction logs. However you could use TRUNCATE to get around this as it won't affect the transaction log.

    Do you have the option of a MERGE/UPSERT? If you're using MS-SQL you can use CROSS APPLY to do something similar if you don't.

提交回复
热议问题