MySQL触发器,一直显示语法错误,说分号不对?
create trigger trigger_course
after insert on course_course for each row
begin
declare sid varchar(8);
declare sname varchar(20);
select logic_id into sid from course_selectcourse where id=new.course;
select name into sname from course_selectcourse where id=new.course;
update course_course
set sub_logic_id=sid, sub_name=sname
where id=new.id;
end;
22:28:06 create trigger trigger_course after insert on course_course for each row begin declare sid varchar(8) Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4 0.000 sec
一方面是已采纳的老哥说的那个问题,另一方面是update循环触发触发器也有问题。
记录一下正确写法:
drop trigger if exists trigger_course;
delimiter $$
create trigger trigger_course
before insert on course_course for each row
begin
declare sid varchar(8);
declare sname varchar(20);
select logic_id into sid from subject_subject where id=new.subject_id;
select name into sname from subject_subject where id=new.subject_id;
set new.sub_logic_id=sid, new.sub_name=sname;
end;
$$
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
定义过程函数和触发器等要先重新定义分隔符
如
delimiter $$
, 这是因为分号此时并不是语义的结束, 而只是你要定义的实体的一部分.试试下面的代码