Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 17:51:41
Original
2351 people have browsed it

本文章分享一篇关于在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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!