在MySQL中创建触发器,提示错误,错误在哪? 5
createtriggertri_crkoncrkbforinsertAsDeclare@crchar(2),@wlnumchar(7),@cknumchar(7),@s...
create trigger tri_crk on crkb for insert
As
Declare @cr char(2),@wlnum char(7),@cknum char(7),@sl int
Select @cr=cr from inserted
Select @wlnum=wlmun from inserted
Select @cknum=cknum from inserted
Select @sl=sl from inserted
If @cr=’入’
Begin
If @wlnum not int(select wlnum from ckb)
Inserted ckb(cknum,wlnum) values(@cknum,@wlnum)
Update ckb set wlsl=wlsl+@sl where cknum=@cknum and wlnum=@wlnum
End
Else
Begin
If(select sl from ckb where wlnum=@wlnum and cknum=@cknum)<@sl
Print’物料不足’
Rollback
End
Update ckb set wlsl=wlsl-@sl where cknum=@cknum and wlnum=@wlnum
Go
错误代码 1064,SQL 状态 42000:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'On crkb for insert
As
Declare @cr char(2),@wlnum char(7),@cknum char(7),@sl int
' at line 2 展开
As
Declare @cr char(2),@wlnum char(7),@cknum char(7),@sl int
Select @cr=cr from inserted
Select @wlnum=wlmun from inserted
Select @cknum=cknum from inserted
Select @sl=sl from inserted
If @cr=’入’
Begin
If @wlnum not int(select wlnum from ckb)
Inserted ckb(cknum,wlnum) values(@cknum,@wlnum)
Update ckb set wlsl=wlsl+@sl where cknum=@cknum and wlnum=@wlnum
End
Else
Begin
If(select sl from ckb where wlnum=@wlnum and cknum=@cknum)<@sl
Print’物料不足’
Rollback
End
Update ckb set wlsl=wlsl-@sl where cknum=@cknum and wlnum=@wlnum
Go
错误代码 1064,SQL 状态 42000:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'On crkb for insert
As
Declare @cr char(2),@wlnum char(7),@cknum char(7),@sl int
' at line 2 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
If @wlnum not int(select wlnum from ckb)
这里的int-->in算一个吧
另外你要把错误提示一并贴出来才好判断
这里的int-->in算一个吧
另外你要把错误提示一并贴出来才好判断
追问
还是有错
追答
在手机上没注意整体代码,你这是MSSQL的语法在MySQL下肯定全挂啊。
请参考如下,触发器on表crkb、级联更新表ckb?此前提。
CREATE TRIGGER `tri_crk` AFTER INSERT ON `crkb` FOR EACH ROW
begin
if new.sl = '入' then
/*假设有复合主键cknum,wlnum,数量列wlsl*/
insert into ckb(cknum,wlnum,wlsl) values(new.cknum,new.wlnum,new.sl) ON DUPLICATE KEY UPDATE wlsl = wlsl + new.sl;
else
/*条件and wlsl > new.sl限定保证够数才扣*/
update ckb set wlsl=wlsl-new.sl where cknum=new.cknum and wlnum=new.wlnum and wlsl > new.sl;
end if;
end;
有待完善
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询