在插入操作中创建触发器 [英] Create a Trigger in insert operation
本文介绍了在插入操作中创建触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的以下查询出了什么问题
What''s wrong with my following query
create trigger newcall on callbook
after insert
as
begin
declare @new=select max(new) from tblMRM where month=month(getdate()) and year=year(getdate());
update tblMRM SET new=@new+1 where month=month(getdate()) and year=year(getdate());
GO
这里 callbook 是表.当 callbook 中发生插入操作时,我想将表 tblMRM 的new(文件名)的值增加1.
当我执行查询时,它显示以下错误:
here callbook is table.When insert operation occur in callbook then I want to increase value of new(filed name) of table tblMRM by one.
When I execute my query ,it show following error:
Msg 102, Level 15, State 1, Procedure newcall, Line 5
Incorrect syntax near '='.
Msg 137, Level 15, State 2, Procedure newcall, Line 6
Must declare the scalar variable "@new".
请帮忙...
我是触发器的新手...
please help...
I am new in trigger...
推荐答案
检查此
Hi ,
Check this
create trigger newcall on callbook
after insert
as
begin
declare @new int --here what you missed
select @new=(select max(new) from tblMRM where month=month(getdate()) and year=year(getdate()))
update tblMRM SET new=@new+1 where month=month(getdate()) and year=year(getdate());
GO
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于在插入操作中创建触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文