表是mood
里面有moodID,replyMoodID,replynum三个属性,replyMoodID参照moodID,
本人想写一个触发器当新增加一列时,假如replyMoodID不为0时,在相应moodID的replynum上加一
本人不知道my sql的语句和sql server有什么不一样,写
create TRIGGER replyMood
after insert on mood
as
BEGIN
declare num int
select num=replynumID from inserted
if num!=0 THEN
update mood set replynum=replynum+1 where moodID=num
END
总是出错,在sql server里写
create TRIGGER replyMood
on mood after insert
as
BEGIN
declare @num int
select @num=replyID from inserted
if @num!=0
update mood set replynum=replynum+1 where moodID=@num
END
就没问题,求指点
里面有moodID,replyMoodID,replynum三个属性,replyMoodID参照moodID,
本人想写一个触发器当新增加一列时,假如replyMoodID不为0时,在相应moodID的replynum上加一
本人不知道my sql的语句和sql server有什么不一样,写
create TRIGGER replyMood
after insert on mood
as
BEGIN
declare num int
select num=replynumID from inserted
if num!=0 THEN
update mood set replynum=replynum+1 where moodID=num
END
总是出错,在sql server里写
create TRIGGER replyMood
on mood after insert
as
BEGIN
declare @num int
select @num=replyID from inserted
if @num!=0
update mood set replynum=replynum+1 where moodID=@num
END
就没问题,求指点
解决方案
10
MySQL同SQL SERVER在触发器语法还是有区别的,你最好先一下MySQL的帮助文档,便于理解学习
25
敲错数字,把!=5改为!=0
drop trigger if exists replyMood; delimiter || create trigger replyMood before insert on mood for each row begin if new.replynumID!=0 then set new.moreplynumnth=new.replynum+1; end if ; end || delimiter ;
5
Z_last
结帖率:0%
结帖率:0%