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

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将终止该进程

触发器出什么问题了??



...全文
26 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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 ?
回复
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2003-07-07 07:29
社区公告
暂无公告