I have 2 tables:
id box_name hidden
---------------------------
id item_name box_id hidden
so the foreign key is box_id, if the box is deleted or updated it touches also the child items, but how can I make the same with the hidden fields, they are indexes with the same type int(11), if I hide some box, all the children are hidden, but how to hide only the children who references to the box_id -> id, those hidden???
or in other words, how to make 2 foreign keys
You can easily do this by adding unique constraint on parent table
id,hiddenfields and changing your detail table so it has FK to (id,hidden) rather than to justid. However, in this case I don’t see why you need to storehiddenattribute in detail table since it’s always the same as parenthidden.I’d rather add an after update trigger on master table that updates all necessary rows in detail table[s].
Update. Example.
1st approach
every time you change
hiddenin boxTable it will be automatically updated inchildTable.2nd approach (double check syntax, I don’t have mysql at the moment)
2nd approach allows you changing
hiddenfields in childTable regardless of value inboxTable, the first doesn’t.