views:

42

answers:

2

Lets say I have two tables, 'a' and 'b'. The relationship of 'a' to 'b' is one to many. Lets both tables have the field status. This field has the values 'active' and 'inactive'. If I set the field status to 'inactive', does MySQL have a way to cascade this down to all tables tied to the row I changed the status value for? Or would this have to be done at the program level?

Let me know if this isn't clear.

Thanks!

+3  A: 

You could use a trigger on the parent table that updates all children as necessary. Otherwise you'll have to handle it at the same level of your application where you update the parent row.

KM
Thanks! I'll check this out.
tappit
A: 

I've never tried this, and I'm not sure if I would recommend it, but if you add the status column to your foreign key (so you have two columns: the primary key of table 'a' and status) and then use on update cascade that might work as well.

Tinister
how would you set the status of the child to inactive, but leave the parent active?
KM
You couldn't. So if you needed to do that, this wouldn't be a solution. Thanks for adding that.
Tinister
Cascading updates can also cause locking issues in many databases. JUst something to think about in designing.
HLGEM