Remove value from database when update

Hi, I’ve got the following table

Schermata 2020-03-01 alle 18.15.30

How would you update the database if one of the option has been thicked and therefore needs to be excluded and deleted from database? What I’ve done so far is to remove all the values from database table and reinsert them excluding the one thicked, but not sure if is the best approach in this case.

How about removing only the ticked value?

1 Like

I think the implication was “Is there a way to do an update and delete in a single query” to wit, no. They’re two separate statements, and you have the two options presented to you: Delete All and Insert the ‘updated’ data (see below) or Delete Target and Update the rest.

The reason you’ll get a lot of leaning towards option 2 is due to disassociation of linked data. If you are foreign keying from this table, deleting the rows and reinserting the same data will presumably generate a new key that no longer matches, breaking your foreign key.

1 Like

Hi @m_hutley thanks for your explanation. I’ll chose to delete the selected and update the rest to prevent problems with foreign keys. I believe I need to perform the update and delete query with a transaction to make sure they are both executed is it correct?