mysql - Updating intersection tables, alternative to delete->insert -
i hope 1 more sql wise can me. suppose following table , relationships they're compacted.
orders(pk_refno,customer, status) order_accessories(pk_refno,pk_acc) accessories(pk_acc,name,desc)
as can see typical 1:*----*:*----*:1
scenario the issue or concern when updating, accessories each order has can modified, meaning user can add/remove accessories.
the way i've thought using mysql delete accessories , insert updated ones.
i dislike way. think there's sql way it. maybe can suggest , advanced query (which i'll study of course)
the other way thought to:
i'm not fan of either because done in app, not in database.
let's table starts this.
order_accessories pk_refno pk_acc 1 73 1 74 1 75 1 86 1 92
let's 75 supposed 76. assuming sane user interface, user can change 75 76. sane user interface send statement dbms.
update order_accessories set pk_acc = 76 (pk_refno = 1 , pk_acc = 75);
if 75 not supposed there in first place, user delete 1 row. sane user interface send statement dbms.
delete order_accessories (pk_refno = 1 , pk_acc = 75);
Comments
Post a Comment