0
votes

I'm trying to delete a student record from the database using the below query. But I face this error.

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

Error report - SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended"

1
See this: stackoverflow.com/questions/12672082. It shows how to delete data based on joins in oracle. Here's another example: dba.stackexchange.com/questions/134622 - zedfoxus
You can't delete from multiple tables with the DELETE statement. - a_horse_with_no_name

1 Answers

2
votes

Give this a shot to delete student record for which there exists an enrollment.

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

If you are interested in deleting a student record from both student table and enrollment table, run 2 queries:

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

If you want to automatically delete enrollment record when you delete a student, you may want to look into triggers.