下面是创建我的表的脚本:
CREATE TABLE clients (
client_i INT(11),
PRIMARY KEY (client_id)
);
CREATE TABLE projects (
project_id INT(11) UNSIGNED,
client_id INT(11) UNSIGNED,
PRIMARY KEY (project_id)
);
CREATE TABLE posts (
post_id INT(11) UNSIGNED,
project_id INT(11) UNSIGNED,
PRIMARY KEY (post_id)
);
在我的PHP代码中,当删除客户端时,我想删除所有项目的帖子:
DELETE
FROM posts
INNER JOIN projects ON projects.project_id = posts.project_id
WHERE projects.client_id = :client_id;
posts表没有client_id
外键,只有project_id
。我想删除已通过client_id
的项目中的帖子。
这是不工作的,因为没有帖子被删除。