The project I'm working on currently has a categories table, as well as a business_category table (an association between a business and its categories). I want to run a query that will update the values in business_category with the new associations, and keep the ones that exist currently.
I know I can do a DELETE
statement to first clear the associations, then do an insert. My question is, is there a better way to do it? Is this performance-savvy? I imagine this query might be called somewhat often, and it seems a bit extreme to delete and re-insert every time it's ran, when really all I want to do is insert if the record doesn't exist already.
For table structure, business_category
is just two columns: business_id
, and category_id
.
Anybody got any ideas? Should I just go ahead and do the delete? Or is there a better way?
Thanks in advance.