我正在使用MYSQL服務器版本:5.5.16並且建立我的第一個觸發器非常困難。希望在更新表時更新基於表中其他值的變量。下面的代碼生成語法錯誤...#1193 - 未知的系統變量「狀態」語法錯誤定義MYSQL觸發器
CREATE TABLE `peakstat` (
`peakuid` int(11) NOT NULL AUTO_INCREMENT,
`status` varchar(20) ,
`scheddate` date ,
`summitdate` date ,
PRIMARY KEY (`peakuid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
,並建立了扳機......
delimiter $$
drop TRIGGER if exists addstatus $$
CREATE TRIGGER addstatus
AFTER UPDATE ON peakstat
FOR EACH ROW
BEGIN
IF peakstat.summitdate > 0 THEN
set peakstat.status = "CLIMBED";
ELSEIF peakstat.scheddate > NOW() THEN
set peakstat.status = "SCHEDULED";
END IF;
END;$$
DELIMITER ;
包裹帶回蜱' – diEcho
澄清:的[MySQL的'peakstat'.'status' – LeleDumbo
可能重複插入後和更新後觸發](http://stackoverflow.com/questions/843031/mysql-after-insert-and-after-update-trigger) –