这是查询:
DELETE FROM patientpersonal,patientmedical,patientdental
WHERE patientpersonal.'" & dpatientid & "' = patientmedical.'" &
dpatientid & "' AND patientpersonal.'" & dpatientid & "' = patientdental.'"
& dpatientid & "'
它有MySQL 1064的错误
答案 0 :(得分:1)
对我来说,似乎您希望将三个语句包装到一个存储过程中。您可以将ID作为参数传递到存储过程中,然后运行三个delete语句。它很简单,可以是事务性的,因此您可以确保它不会部分执行。
如果需要,这是MySQL存储过程的良好入门链接: http://net.tutsplus.com/tutorials/an-introduction-to-stored-procedures/
我无法对此进行测试,因此它可能有点偏差,但您的存储过程应该如下所示:
CREATE PROCEDURE sprocDeleteAllInfo(IN my_id INT)
BEGIN
START TRANSACTION;
DELETE FROM patientpersonal WHERE patientid = my_id;
DELETE FROM patientmedical WHERE patientid = my_id;
DELETE FROM patientdental WHERE patientid = my_id;
COMMIT;
END
答案 1 :(得分:0)
您需要分别从每个表中删除。
DELETE FROM patientpersonal WHERE patientid = ?
DELETE FROM patientmedical WHERE patientid = ?
DELETE FROM patientdental WHERE patientid = ?
或者你可以为你的病人表设置一个外键ON DELETE CASCADE
,如果这是你想要的。