create trigger xxxx on table2 after insert as
update t1 set atonum=atonum-i.atonum
from table1 as t1 inner join inserted as i on t1.aid=i.aid
go注意这里假设 aid 的值是唯一的。
update t1 set atonum=atonum-i.atonum
from table1 as t1 inner join inserted as i on t1.aid=i.aid
go注意这里假设 aid 的值是唯一的。
CREATE TABLE t2(aid INT,num INT)INSERT INTO t1 SELECT 1001,100 UNION SELECT 1002,200CREATE TRIGGER tri_ins
on t2
FOR INSERT
ASupdate t1 set atotnum=atotnum-i.num from INSERTED i where i.aid=t1.aid
INSERT INTO t2 values (1001,10)SELECT * from t1
SELECT * from t2select * from t1
select * from t2
update t1 set atonum=atonum-i.atonum
from table1 as t1 inner join inserted as i on t1.aid=i.aid
go
FOR INSERT, UPDATE ---当插入或修改时触发
AS
declare @num int
select num=@num from inserted
update table1 set atotnum=atotnum-@num from inserted a,table2 b where a.aid=b.aid
CREATE TRIGGER 触发器名 ON 表名
FOR INSERT, UPDATE ---当插入或修改时触发
AS
declare @num int
select @num=num from inserted
update table1 set atotnum=atotnum-@num from inserted a,table2 b where a.aid=b.aid 上面这个决对行,不行你砍我.
语句中都有“inserted as i”,这"inserted"作何解?
还有什么不明白吗?