我是这样写的,不知行不行: CREATE TRIGGER [produce_project_detail delete] ON [dbo].[produce_project_detail] FOR DELETE AS if (select count(*) from noproduce_informdetail,deleted d where noproduce_informdetail.orderformid=d.orderformid and noproduce_informdetail.orderformitem=d.orderformid)=0 begin INSERT INTO ..... end else update......
UP,不知我那句COUNT写得对不对,在末下生产通知单中,以订单号和订单明细项为主键!
count(*)... =0 是对的,但是最好写成 CREATE TRIGGER [produce_project_detail delete] ON [dbo].[produce_project_detail] FOR DELETE AS if not exists (select 1 from noproduce_informdetail,deleted d where noproduce_informdetail.orderformid=d.orderformid and noproduce_informdetail.orderformitem=d.orderformid) begin INSERT INTO ..... end else begin update...... end
CREATE TRIGGER [produce_project_detail delete] ON [dbo].[produce_project_detail]
FOR DELETE
AS
if (select count(*)
from noproduce_informdetail,deleted d
where noproduce_informdetail.orderformid=d.orderformid and
noproduce_informdetail.orderformitem=d.orderformid)=0
begin
INSERT INTO .....
end else
update......
CREATE TRIGGER [produce_project_detail delete] ON [dbo].[produce_project_detail]
FOR DELETE
AS
if not exists (select 1
from noproduce_informdetail,deleted d
where noproduce_informdetail.orderformid=d.orderformid and
noproduce_informdetail.orderformitem=d.orderformid)
begin
INSERT INTO .....
end
else
begin
update......
end