CREATE TRIGGER `before_insert_table_name` BEFORE INSERT ON `table_name`
FOR EACH ROW
BEGIN
SET `NEW`.`z` = `NEW`.`x` + `NEW`.`y`;
END
CREATE TRIGGER `before_update_table_name` BEFORE UPDATE ON `table_name`
FOR EACH ROW
BEGIN
IF (`OLD`.`x` <=> `NEW`.`x`) = 0 OR (`OLD`.`y` <=> `NEW`.`y`) = 0 THEN
SET `NEW`.`z` = `NEW`.`x` + `NEW`.`y`;
END IF;
END