CREATE table A1
(
a int,
b int,
c int
)
CREATE table A2
(
a int,
b int,
c int,
d int,
e int
)
GO
CREATE TRIGGER [xjzc] ON [dbo].[A1]
FOR INSERT, UPDATE, DELETE
AS
if exists (select * from A2 where b=(select b from inserted) and c=(select c from inserted))
update a set a.lysl=isnull(a.a,0)+isnull(b.a,0) from A2 a,consuming b where a.b=b.b and a.c=b.c
else
insert A2 select *,null,null from inserted
--insert A2 select * from inserted 这个不行,为什么?因为A2表要5个字段的数据,inserted只有3个
--现在用null,null2个补一下
GO
insert into A1
select 3,2,7
select * from A1
select * from A2
可以,这没关系的
这个完全是没有问题的,关键问题是触发器要实现什么功能
可以