从两个表中删除联接 [英] Delete join from two tables

查看:88
本文介绍了从两个表中删除联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个联接,该联接将删除两个表中的条目.当表中的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆