批量更新触发器问题?

wth1150 2006-09-27 07:28:44
触发器:当更新的数据COL004字段为NULL时,不更新,保留更新前的值。单个测试没问题
但批量更新的时候DELETED表保存了所有更新前的数据。求解!
CREATE TRIGGER tri_update_fax ON [dbo].[test]
FOR UPDATE
AS
declare @old_text varchar(50)
declare @new_text varchar(50)
select @old_text=col004 from deleted
select @new_text=col004 from test where col001=(select col001 from deleted)
if @new_text is null
begin
update test set col004=@old_text where col001=(select col001 from deleted)
end
...全文
162 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wth1150 2006-09-27
  • 打赏
  • 举报
回复
THANKS问题解决
pbsql 2006-09-27
  • 打赏
  • 举报
回复
yes
zicxc 2006-09-27
  • 打赏
  • 举报
回复
楼上的触发器应该不对

CREATE TRIGGER tri_update_fax ON [dbo].[test]
FOR UPDATE
AS

update test set col004=d.col004
from test t,inserted i,deleted d
where t.col001=i.col001 and i.col001=d.col001 and i.col004 is null

go

or:

CREATE TRIGGER tri_update_fax ON [dbo].[test]
FOR UPDATE
AS

update test set col004=d.col004
from test t,deleted d
where t.col001=d.col001 and t.col004 is null

go
pbsql 2006-09-27
  • 打赏
  • 举报
回复
批量更新时触发器不起作用,那是因为你的触发器代码有问题,你只处理了一条数据

CREATE TRIGGER tri_update_fax ON [dbo].[test]
FOR UPDATE
AS
update test set col004=i.col004
from test t,inserted i,deleted d
where t.col001=i.col001 and i.col001=d.col001 and i.col004 is not null
点点星灯 2006-09-27
  • 打赏
  • 举报
回复
批量更新时触发器不起作用

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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