mysql中多表关联删除,怎样做?谢谢...
6个回答
展开全部
1、现在我们以查询员工角色和权限为例:select * from member m left join member_role mr on m.mid=mr.mid left join role r on mr.rid=r.rid。
2、执行sql执行计划,查看mysql的sql执行结果。现在表进行了全表扫描了。
3、现在在所有的右表上建立一个索引:create index mr_index on member_role(mid)。
4、建立好索引之后重新执行sql执行计划。 explain select * from member m left join member_role mr on m.mid=mr.mid left join role r on mr.rid=r.rid。
5、因此索引最好设置在需要进场查询的字段中。
6、尽可能减少join语句中循环的总次数,永远用小结果集驱动大的结果集。当无法保证被驱动表的join条件字段被索引且内存资源充足的前提下,不要吝啬JoinBuffer的设置。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-08-19
展开全部
mysql中多表关联删除,怎样做?
两个表比如delete后面是要删除的表on是关联的字段where是条件
delete a,b from `ecs_goods` as a join `ecs_goods_gallery` as b on a.goods_id = b.goods_id where a.id ='123'
三个表(依次类推)
delete a,b,c from `ecs_goods` as a join
`ecs_goods_gallery` as b on a.goods_id = b.goods_id join
`ecs_goods_cat` as c on a.goods_id = c.goods_id where a.id
='123'
两个表比如delete后面是要删除的表on是关联的字段where是条件
delete a,b from `ecs_goods` as a join `ecs_goods_gallery` as b on a.goods_id = b.goods_id where a.id ='123'
三个表(依次类推)
delete a,b,c from `ecs_goods` as a join
`ecs_goods_gallery` as b on a.goods_id = b.goods_id join
`ecs_goods_cat` as c on a.goods_id = c.goods_id where a.id
='123'
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
两个表比如delete后面是要删除的表on是关联的字段where是条件
delete a,b from `ecs_goods` as a join `ecs_goods_gallery` as b on a.goods_id = b.goods_id where a.id ='123'
三个表(依次类推)
delete a,b,c from `ecs_goods` as a join
`ecs_goods_gallery` as b on a.goods_id = b.goods_id join
`ecs_goods_cat` as c on a.goods_id = c.goods_id where a.id
='123'
delete a,b from `ecs_goods` as a join `ecs_goods_gallery` as b on a.goods_id = b.goods_id where a.id ='123'
三个表(依次类推)
delete a,b,c from `ecs_goods` as a join
`ecs_goods_gallery` as b on a.goods_id = b.goods_id join
`ecs_goods_cat` as c on a.goods_id = c.goods_id where a.id
='123'
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
给你举个例子
select * from 表1 join 表2 on 表1.字段名=表2.字段名 join 表3 on 表1.字段名=表3.字段名
你可以用left join ,多一个表 在后面按照规律加上即可
select * from 表1 join 表2 on 表1.字段名=表2.字段名 join 表3 on 表1.字段名=表3.字段名
你可以用left join ,多一个表 在后面按照规律加上即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询