OKyJIucT
3/6/2016 - 1:51 PM

Триггер

Триггер

delimiter //
CREATE TRIGGER `update_count_ads` 
AFTER INSERT ON `ads`
FOR EACH ROW 
BEGIN
	UPDATE `counters` SET `value` = `value` + 1 WHERE `id` = 1;
END;
//
delimiter ;

DROP TRIGGER IF EXISTS deleteUser;

delimiter //
CREATE TRIGGER update_saled_ads BEFORE UPDATE ON `ads`
FOR EACH ROW
BEGIN
	IF NEW.status = 'saled' THEN
		UPDATE `counters` SET `value` = `value` + 1 WHERE `id` = 2;
	END IF;
END;
//
delimiter ;