mysql - Indicate the foreign key about change in data -
hi using foreign key reference in table 2
. suppose user has changed data in table 1
referred foreign key in table 2
. there way (or flag) indicate in table 2
data has been changed in table 1
. please suggest me if possible or not. using mysql database.
mr. white's answer correct updating / deleting automatically, won't "flag" updated information, how interpreted question. if want set value of "flag" column when row in table 1
updated, should triggers.
note the docs say:
cascaded foreign key actions not activate triggers.
so setting table 1
cascade
keyword not activate custom code in foreign key table (table 2
) in example - have put trigger on table 1
instead.
from the docs, possible trigger events are:
insert
- whenever new row inserted (viainsert
,load_data
,replace
, etc.)update
- whenever row modifieddelete
- whenever row deleted (viadelete
,replace
, notdrop_table
ortruncate_table
)
and can go either before
or after
event. in case, after
appropriate, execute if statement triggering successful. body of trigger can statement or stored routine, contents of of course depend on actual table structures.
a quick search turned number of questions defining triggers sort of behavior, might point in right direction specific setup:
- mysql after insert trigger updates table's column
- mysql trigger update select table
- mysql trigger - update table value selected table
- create trigger mysql update or insert in table
more info on using triggers: https://dev.mysql.com/doc/refman/5.6/en/triggers.html
Comments
Post a Comment