CREATE TRIGGER 名1 ON table1 FOR INSERT AS update table2 set count1=count1+(select count(*) from inserted)
55.555 看错题目,还以为是要加一CREATE TRIGGER 名1 ON table1 FOR INSERT AS update table2 set count1=count1+(select sum(1) from inserted)
应该没问题吧? CREATE TRIGGER 名1 ON table1 FOR INSERT AS update table2 set count1=count1+1
CREATE TRIGGER 名1 ON table1 FOR INSERT AS update table2 set count1=count1+1 这样写不行,我就是这样写的,当使用查询分析器同时插入500条数据时,count1应该加500,但是这样写count1就加1了,应该使用count1=count1+(select count(*) from inserted),但用count1=count1+1为什么不行呢,高手能分析一下原因吗?谢谢
原因很简单,“同时插入”大概是指“insert... select ... union all select ... [union all select ...]”模式吧!这只会触发一次触发器。
FOR INSERT
AS
update table2 set count1=count1+(select count(*) from inserted)
FOR INSERT
AS
update table2 set count1=count1+(select sum(1) from inserted)
CREATE TRIGGER 名1 ON table1
FOR INSERT
AS
update table2 set count1=count1+1
FOR INSERT
AS
update table2 set count1=count1+1
这样写不行,我就是这样写的,当使用查询分析器同时插入500条数据时,count1应该加500,但是这样写count1就加1了,应该使用count1=count1+(select count(*) from inserted),但用count1=count1+1为什么不行呢,高手能分析一下原因吗?谢谢