Delete and insert vs Update rows in a table

I have a web form where a user can select many available elements (idFamilia) for one provider (idProveedor) that looks like this

next item

The values ​​are stored in this table

-----------------------------
| idProveedor | idFamilia   | 
-----------------------------
|      5      |      1      |
-----------------------------
|      5      |      2      |
-----------------------------
|      6      |      2      |
-----------------------------

      

Once a Provider has been created, it can be edited and the values ​​selected for idFamilia can be changed. So I have three different scenarios for what might happen:

  • The number of lines remains the same and I only need to edit the idFamilia values.
  • Some elements have been removed from the selection and I will need to look for values ​​in the table and delete those rows.
  • New items have been added and I will need to add these additional values.

Right now I'm thinking about just deleting all lines with the idProveedor that is being edited and just inserting a new selection.

Is this good practice? Will it affect performance in the long run?

Could you recommend a tutorial or example to do this in a different way?

+3


source to share


1 answer


I always try to delete and recreate them.



While this adds some performance limitations, it keeps the code simple to understand and easy to maintain. Unless you are Uber, Google, Facebook, Amazon, or any other global application, the benefits you get from optimization are much less than the costs they incur in development, debugging, and maintenance.

+4


source







All Articles