从两个表中删除联接 [英] Delete join from two tables
问题描述
我需要创建一个联接,该联接将删除两个表中的条目.当表中的project_id等于php文档页面上的project_id时,将在项目中进行删除.我还需要删除project_course上的链接条目.这是我目前的代码.
I need to create a join that will delete the entries in two tables. The delete will happen in projects when the project_id in the table is equal to the one on the page of the php document. I need the link entries on project_course to also be deleted. This is the code I have currently.
$deleteSQL = sprintf("DELETE FROM projects p
INNER JOIN project_course pc
WHERE p.Project_id=%s",
GetSQLValueString($_GET['Project_id'], "int"));
有人知道该怎么做吗?我以前没有做过要删除的联接,只是普通联接.
Anybody know how to do this? I haven't done a join to delete before, just a normal join.
推荐答案
不必对联接的查询进行显式操作.可以在表定义中使用DELETE CASCADE
.请参考如何在mysql中删除级联?
You dont have to explicitly do this with joined queries.You can use DELETE CASCADE
in table definition. Refer How do I use on delete cascade in mysql?
这篇关于从两个表中删除联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!