删除时出现错误:SQL错误:ORA-00933:SQL命令未正确结束

我正在尝试使用以下查询从数据库中删除学生记录。但是我遇到这个错误。

DELETE student, enrolment FROM student INNER JOIN enrolment
WHERE student.stu_nbr=enrolment.stu_nbr and student.stu_nbr = 154;

错误报告 - SQL错误:ORA-00933:SQL命令未正确结束 00933. 00000-“ SQL命令未正确结束”

评论
ut_et
ut_et

试一下以删除已有注册的学生记录。

delete from student s
where stu_nbr = 154
  and exists (
    select 1
    from enrollment
    where stu_nbr = s.stu_nbr
  );

如果您有兴趣从学生表和注册表中删除学生记录,请运行2个查询:

delete from enrollment where stu_nbr = 154;
delete from student where stu_nbr = 154;

如果要在删除学生时自动删除注册记录,则可能需要调查触发器。

点赞
评论