如何在MySQL中级联更新?
发布时间:2021-03-15 05:31 所属栏目:115 来源:网络整理
导读:我们来看看这个示例数据库: 我们可以看到,人依赖于城市(person.city_id是外键).我不删除行,我只是将它们设置为非活动状态(active = 0).设置城市无效后,如何自动设置所有依赖此城市的人员?有没有比编写触发器更好的方法? 编辑:我只对设置人的行不活动感兴
我们来看看这个示例数据库: 我们可以看到,人依赖于城市(person.city_id是外键).我不删除行,我只是将它们设置为非活动状态(active = 0).设置城市无效后,如何自动设置所有依赖此城市的人员?有没有比编写触发器更好的方法? 编辑:我只对设置人的行不活动感兴趣,而不是将它们设置为活动状态. 最佳答案 这是一个使用级联外键来执行您所描述的解决方案的解决方案:
在MySQL 5.5.31上测试过. (编辑:ASP站长网) |
相关内容
网友评论
推荐文章
热点阅读