[英]MySQL Trigger to INSERT to table after UPDATE on another table?
我正在嘗試創建一個TRIGGER,它將在更新另一個表之后更新一個表。 我需要它,以便如果更新number列中的數字,則需要將其記錄在另一個表中。 這是我到目前為止所擁有的..
DELIMITER $$
CREATE TRIGGER record_update_to_user_number
AFTER UPDATE ON user FOR EACH ROW
IF (NEW.number != OLD.number) THEN//if new updated number is not equal t to number currently in the table then..
DECLARE insertednumber TINYINT; //variable to store updated num
SET insertednumber = NEW.number;
INSERT INTO user_changes (username, currentdate, numberchange)
VALUES (current_user(), CURDATE(), insertednumber);
END IF;
DELIMITER ;
測試表更新:
UPDATE user SET number='69' WHERE number='68'; //test update to table
如您所見,我正在嘗試將新插入的用戶號存儲到一個變量中,然后該變量將用於填充user_changes表的insertnumber列。 任何幫助將不勝感激,謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.