为什么这个触发器不能按我想要的方式工作?
我的 mysql 数据库中有两个表: 顾问:id 学生:advisorID | 我想更新学生
,其中顾问中删除的 ID 等于顾问 ID,并使用一组 if 语句根据该学生的专业更改该学生的顾问 ID 值。这就是我到目前为止所得到的:
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//
欢迎任何帮助。谢谢。
I have two tables in my mysql database:
Advisor: id
Student: advisorID | major
I want to update Student where the deleted ID in Advisor is equal to advisorID and use a set of if statements to change that student's advisorID value based on that student's major. This is what I have thus far:
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//
Any help is welcome. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这个
UPDATE/IF
ELSEIF
语法,但CASE
语句适合您:I don't know this
UPDATE/IF
ELSEIF
syntax, butCASE
statement will work for you: