Home  >  Article  >  Database  >  mysql中多表关联删除数据时同时删除关联数据

mysql中多表关联删除数据时同时删除关联数据

WBOY
WBOYOriginal
2016-06-07 17:51:412353browse

本文章分享一篇关于在mysql中多表关联删除数据时同时删除关联数据做法,有需要了解的朋友可以参考一下本文章。

category(栏目信息表)和news(新闻数据表)。

category中的id(栏目编号)字段作为该表的主键(primary key).唯一标识了一个栏目的信息。
news 中的id字段作为该表的主键(primary key).唯一标识了一个栏目的信息。

category_id(栏目编号)字段与category表的id字段相关联。

1.SQL删除语句

 代码如下 复制代码

sql = "delete category,news from category left join news on category.id = news.category_id

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn