2 qq 35649402 qq_35649402 于 2017.09.07 09:16 提问

关于mysql触发器根据条件更新的问题! 3C

a表:

id (key)
deviceid
devicename
brand 

b表:

 id (key)
deviceid(key)联合主键
devicename
brand 

请问如何才能做到到b表插入deviceid时,如果a.deviceid=b.deviceid则更新b.devicename and b.brand
我的写法是

BEGIN
UPDATE b SET 
devicename = new.devicename,
brand = new.brand
WHERE deviceid  = (SELECT deviceid FROM a WHERE  brand = new.brand and devicename = new.devicename and brand = new.brand );

但是这样不对,请问大神改怎么做?

3个回答

devmiao
devmiao   Ds   Rxr 2017.09.07 09:32
jiangop
jiangop   2017.09.07 13:47

WHERE deviceid = () “等号绝对出错”

qq_35649402
qq_35649402 生成触发器的时候没有报错,只有在b表插入数据才会报错!
2 个月之前 回复
qq_35649402
qq_35649402   2017.09.07 15:17

关闭问题提高C币悬赏

Csdn user default icon
上传中...
上传图片
插入图片