MySQL触发器,A表关联B表,B表关联C表。要求A表插入数据时把C表x字段插入到A表

x_a 商品入库 字段:productsid商品id、categoryname类别名称

x_b 商品信息 字段:id商品id、categoryid类别id

x_c 商品类别 字段:id类别id、categoryname类别名称

x_a表productsid关联x_b的id,x_b表categoryid关联x_c的id

x_a表插入数据时将 x_c的categoryname类别名称 插入到 x_a的categoryname类别名称

https://blog.csdn.net/qq_36020545/article/details/76502233

insert into x_a(productid,categoryname)
select productid ,categoryname
from x_b b
join x_c c on b.categoryid=c.id
where b.id=@id

将@id改为实际商品id