除了 notes 表之外,我还将这个相同的触发器应用于大约 15 个其他表。不确定,但似乎存储过程会消除重复的代码。这是存储过程的好应用程序吗?如果是这样,如何实施?
CREATE TRIGGER tg_notes_ins BEFORE INSERT ON notes FOR EACH ROW
BEGIN
IF NEW.created_by_user IS NULL OR NEW.created_by_user = '' THEN
SET NEW.created_by_user = @users_id;
END IF;
IF NEW.modified_by_user IS NULL OR NEW.modified_by_user = '' THEN
SET NEW.modified_by_user = @users_id;
END IF;
END$$
CREATE TRIGGER tg_notes_upd BEFORE UPDATE ON notes FOR EACH ROW
BEGIN
IF NEW.modified_by_user = OLD.modified_by_user THEN
SET NEW.modified_by_user = @users_id;
END IF;
END$$