I have a relationships table, the table looks something like this
------------------------
| client_id | service_id |
------------------------
| 1 | 1 |
| 1 | 2 |
| 1 | 4 |
| 1 | 7 |
| 2 | 1 |
| 2 | 5 |
------------------------
I have a list of new permissions I need to add, what I’m doing right now is, for example, if I have to add new permissions for the client with id 1, i do
DELETE FROM myTable WHERE client_id = 1
INSERT INTO ....
Is there a more efficient way I can remove only the ones I won’t insert later, and add only the new ones?
yes, you can do this but in my humble opinion, it’s not really
sqldependent subject. actually it depends on your language/platform choice. if you use a powerful platform like.NETorJava, there are many database classes likeadapters,datasetsetc. which are able to take care of things for you like finding the changed parts, updating/inserting/deleting only necessery parts etc.i prefer using
hibernate/nhibernatelike libraries. in this case, you don’t even need to write sql queries most of the time. just do the things at oop level and synchronize with the database.