34,593
社区成员
发帖
与我相关
我的任务
分享
create trigger dbo.trigger_table1_update
on dbo.table1
as
if exists(select a from deleted where a is not null) and
(update(a) or UPDATE(b))
begin
update table1
set c = null
from inserted i
where table1.id = i.id
end
if exists(select a from deleted where a is null) and
(update(d) or UPDATE(b))
begin
update table1
set c = null
from inserted i
where table1.id = i.id
end
go
[/quote]
(update(a) or UPDATE(b))这样不行,如果新值旧值一样,它仍认为是发生了变化。[/quote]
那就用上面的ap0405140的,应该可以的
create trigger dbo.trigger_table1_update
on dbo.table1
as
if exists(select a from deleted where a is not null) and
(update(a) or UPDATE(b))
begin
update table1
set c = null
from inserted i
where table1.id = i.id
end
if exists(select a from deleted where a is null) and
(update(d) or UPDATE(b))
begin
update table1
set c = null
from inserted i
where table1.id = i.id
end
go
[/quote]
(update(a) or UPDATE(b))这样不行,如果新值旧值一样,它仍认为是发生了变化。
create trigger tr_table1
on table1 for update
as
begin
update a
set a.C字段=null
from table1 a
where exists
(select 1
from deleted b
inner join inserted c on b.id=c.id
where b.id=a.id and b.A字段 is not null and (b.A字段<>c.A字段 or b.B字段<>c.B字段))
or exists
(select 1
from deleted b
inner join inserted c on b.id=c.id
where b.id=a.id and b.A字段 is null and (b.D字段<>c.D字段 or b.B字段<>c.B字段))
end
create trigger dbo.trigger_table1_update
on dbo.table1
as
if exists(select a from deleted where a is not null) and
(update(a) or UPDATE(b))
begin
update table1
set c = null
from inserted i
where table1.id = i.id
end
if exists(select a from deleted where a is null) and
(update(d) or UPDATE(b))
begin
update table1
set c = null
from inserted i
where table1.id = i.id
end
go