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 (via insert, load_data, replace, etc.)
  • update - whenever row modified
  • delete - whenever row deleted (via delete, replace, not drop_table or truncate_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:

more info on using triggers: https://dev.mysql.com/doc/refman/5.6/en/triggers.html


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -