I have two tables, one for storing reports of a user, and another for storing users.
1. Report_table
-----report_id(P)-----user_id--------
001
You need a trigger: http://dev.mysql.com/doc/refman/5.6/en/trigger-syntax.html which should fire after each insert operation on the reports_table.
CREATE TRIGGER update_report_cnt AFTER INSERT ON reports_table
FOR EACH ROW
BEGIN
UPDATE users_table SET no_of_reports = no_of_reports + 1 where user_id = NEW.user_id;
END;
(I'm not sure the syntax is correct. Ithink a before insert trigger would also work)
You can deal with TRIGGER
by using a AFTER INSERT
trigger
http://dev.mysql.com/doc/refman/5.0/en/triggers.html