日期:2014-05-18 浏览次数:20570 次
CREATE TABLE temp_2(c1 INT,c2 INT ) CREATE TABLE temp_2(c1 INT,c2 INT ) INSERT INTO temp_2(c1,c2) VALUES(1,1),(2,2),(3,3) INSERT INTO temp_1(c1,c2) VALUES(1,1),(1,2),(1,3)
ALTER TRIGGER tr_1 ON temp_1 after INSERT,update as begin UPDATE a SET a.c2 = b.c2 FROM temp_2 a,INSERTED b WHERE a.c1=b.c1 AND EXISTS(SELECT MAX(c2) FROM temp_1 WHERE c1 =INSERTED.c1 GROUP BY c1 ) END
AND EXISTS(SELECT MAX(c2) FROM temp_1 WHERE c1 =INSERTED.c1 GROUP BY c1 )