触发器哪里有问题么??为什么新增纪录时总是报错,无法保存,谢谢大家指教!

booksfount 2003-07-07 07:29:54
有一个表,我写了2个触发器,分别是for update and for insert

详细如下:
CREATE TRIGGER tri_depose ON fgoodinout
FOR update
AS
declare @fg_hand numeric,@fg_money numeric,@fg_vcode varchar(4),@fg_depose smallint,@fg_owe numeric
if not update(fg_depose)
begin
commit tran
return
end

select fg_hand=@fg_hand,
fg_money=@fg_money,
fg_vcode=@fg_vcode,
fg_depose=@fg_depose
from inserted

set @fg_owe=@fg_money - @fg_hand

if @fg_depose =1 --1代表有效票据,0代表费票
UPDATE victualer
SET v_money = v_money + @fg_owe
WHERE victualer.v_code = @fg_vcode
else

UPDATE victualer
SET v_money = v_money - @fg_owe
WHERE victualer.v_code = @fg_vcode


if @@error<>0
rollback tran
else
commit tran

触发器2:
CREATE TRIGGER tri_fgoodinout ON fgoodinout
FOR INSERT
AS
declare @fg_hand numeric,@fg_money numeric,@fg_vcode varchar(4),@fg_owe numeric
select fg_hand=@fg_hand,
fg_money=@fg_money,
fg_vcode=@fg_vcode
from inserted

set @fg_owe=@fg_money - @fg_hand

if @fg_owe =0
begin
commit tran
return
end
else

UPDATE victualer
SET v_money = v_money + @fg_owe
WHERE victualer.v_code = @fg_vcode

if @@error<>0
rollback tran
else
commit tran



我直接在sql server中新增行就保存不上(insert操作),错误提示如下:

进程54发生了严重的异常c0000005_EXCEPTION_ACCESS_VIOLATION.sql server将终止该进程

触发器出什么问题了??



...全文
88 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
booksfount 2003-07-07
  • 打赏
  • 举报
回复
谢谢谢谢!:)
97866 2003-07-07
  • 打赏
  • 举报
回复
改了这里:
select @fg_hand=fg_hand,
@fg_money=fg_money,
@fg_vcode=fg_vcode
from inserted
booksfount 2003-07-07
  • 打赏
  • 举报
回复
谢谢:

to 97866(weiLuang)
我保证我每insert一条纪录后,程序都update了,所以inserted表应该是仅有一条记录了,所以我就直接这样写了???
select fg_hand=@fg_hand,
fg_money=@fg_money,
fg_vcode=@fg_vcode
from inserted ?
--------------------------------------
to pengdali(大力 V2.0)
我看了一下,没看出来在哪里改了??可否详细指教一下,谢谢!
pengdali 2003-07-07
  • 打赏
  • 举报
回复
CREATE TRIGGER tri_depose ON fgoodinout
FOR update
AS
declare @fg_hand numeric,@fg_money numeric,@fg_vcode varchar(4),@fg_depose smallint,@fg_owe numeric
if not update(fg_depose)
begin
commit tran
return
end

select @fg_hand=fg_hand,
@fg_money=fg_money,
@fg_vcode=fg_vcode,
@fg_depose=fg_depose
from inserted

set @fg_owe=@fg_money - @fg_hand

if @fg_depose =1 --1代表有效票据,0代表费票
UPDATE victualer
SET v_money = v_money + @fg_owe
WHERE victualer.v_code = @fg_vcode
else

UPDATE victualer
SET v_money = v_money - @fg_owe
WHERE victualer.v_code = @fg_vcode


if @@error<>0
rollback tran
else
commit tran

触发器2:
CREATE TRIGGER tri_fgoodinout ON fgoodinout
FOR INSERT
AS
declare @fg_hand numeric,@fg_money numeric,@fg_vcode varchar(4),@fg_owe numeric
select @fg_hand=fg_hand,
@fg_money=fg_money,
@fg_vcode=fg_vcode
from inserted

set @fg_owe=@fg_money - @fg_hand

if @fg_owe =0
begin
commit tran
return
end
else

UPDATE victualer
SET v_money = v_money + @fg_owe
WHERE victualer.v_code = @fg_vcode

if @@error<>0
rollback tran
else
commit tran
97866 2003-07-07
  • 打赏
  • 举报
回复
select fg_hand=@fg_hand,
fg_money=@fg_money,
fg_vcode=@fg_vcode
from inserted ?

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧