1
我在我的mysql數據庫中有兩個表: 顧問:編號 學生:advisorID |主要爲什麼這個觸發器不按我想要的方式工作?
我想更新學生,其中Advisor中刪除的ID等於advisorID並使用一組if語句來根據該學生的專業更改該學生的advisorID值。這是我迄今爲止:
delimiter //
create trigger advisor_delete after delete
on advisor
UPDATE Student
IF Student.major = 'major1' THEN SET Student.advisorID = 1;
ELSEIF Student.major = 'major2' THEN SET Student.advisorID = 2;
ELSEIF Student.major = 'major3' THEN SET Student.advisorID = 3;
ELSE SET Student.advisorID = 4;
ENDIF;
WHERE Student.advisorID = OLD.id;
end//
任何幫助是值得歡迎的。謝謝。