I am using a database that has 2 tables for city and country. City table has ID(PK), population and country code. Country table has Code(PK) and population. If an update happens to city population, the country population should be updated automatically.The issue is how to implement this in a proper update statement. It should follow the general pattern below:
CREATE TRIGGER diff_pop
AFTER UPDATE
ON city
FOR EACH ROW
...
UPDATE country SET NEW.population=country.population-city_old+city_new
WHERE country.population=new.population;
I think there could be many ways to solve this, so any input is appreciated.