34,571
社区成员
发帖
与我相关
我的任务
分享
create trigger trigger_triggerupdatetable
on T_Test
after update
as
begin
if update([colA])
begin
update T_Test set colB = newvalue;
end
if update([colB])
begin
update T_Test set colC = newvalue;
end
if update([colC])
begin
update T_Test set colD = newValue;
end
end
declare @t table
( dt datetime default(getdate()), y as datepart(yyyy,dt), m as datepart(mm,dt), d as datepart(d,dt) )
insert into @t values ( default )
select * from @t
DECLARE @T_Test TABLE(A int, B int,C int, D int, E int)
INSERT INTO @T_Test
SELECT 0, 0, 1, 0, 1 -- 用这个模拟当前行
SELECT * FROM @T_Test
UPDATE @T_Test
SET B = 2
WHERE B = 0
AND C = 1
AND D = 1
AND E = 1
UPDATE @T_Test
SET A = 2
WHERE A = 0
AND B = 1
PRINT '->'
SELECT * FROM @T_Test
A B C D E
----------- ----------- ----------- ----------- -----------
0 0 1 0 1
->
A B C D E
----------- ----------- ----------- ----------- -----------
0 0 1 0 1
A B C D E
----------- ----------- ----------- ----------- -----------
0 0 1 1 1
->
A B C D E
----------- ----------- ----------- ----------- -----------
0 2 1 1 1
A B C D E
----------- ----------- ----------- ----------- -----------
0 1 1 1 1
->
A B C D E
----------- ----------- ----------- ----------- -----------
2 1 1 1 1
A B C D E
----------- ----------- ----------- ----------- -----------
1 1 1 1 1
->
A B C D E
----------- ----------- ----------- ----------- -----------
1 1 1 1 1