从多个MySQL数据库表中删除

时间:2014-07-28 18:24:27

标签: php mysql sql

为什么当我从MySQL中的多个表中删除数据时没有任何反应呢?我的情况是,当我从大学中删除一所学校时,所有在该学校注册的课程,教师和学生也将被删除。

这是我的工作方式

DELETE FROM university, courses, faculty, students 
INNER JOIN university 
INNER JOIN courses 
INNER JOIN faculty 
INNER JOIN students ON university.id = courses.university_id
AND  courses.id = faculty.courses_id
AND faculty.id = students.faculty_id 
WHERE university.id = :id

PHP代码中的:id = id。

参考:Mysql - delete from multiple tables with one queryhttp://www.mysqltutorial.org/mysql-delete-statement.aspx

1 个答案:

答案 0 :(得分:2)

这是使用

的语法
DELETE university, courses, faculty, students 
FROM university 
INNER JOIN courses ON university.id = courses.university_id
INNER JOIN faculty ON courses.id = faculty.courses_id
INNER JOIN students ON faculty.id = students.faculty_id 
WHERE university.id = :id