22,207
社区成员
发帖
与我相关
我的任务
分享
create table test1 (classid int,nameid int ,record int)
insert test1
select 101,111,99 union all
select 101,111,80 union all
select 101,111,88 union all
select 102,113,66 union all
select 102,113,55
go
create table test2 (classid int,nameid int)
go
create trigger t_test
on test1
for insert, update
as
begin
insert into test2
select distinct classid,nameid
from inserted t
where not exists(select 1 from test2 where classid=t.classid and nameid=t.nameid)
end
insert into test1
select 103,114,44
select * from test1
select * from test2
classid nameid record
----------- ----------- -----------
101 111 99
101 111 80
101 111 88
102 113 66
102 113 55
103 114 44
(所影响的行数为 6 行)
classid nameid
----------- -----------
103 114
(所影响的行数为 1 行)
create trigger t_collect
on tb1
for insert,update
as
begin
insert into tb2
select distinct classid,nameid
from inserteb t
where not exists(select 1 from tb2 where classid=t.classid and nameid=t.nameid)
end
create trigger t_collect
on tb1
for insert,update
as
begin
insert into tb2
select distinct classid,nameid
from inserteb t
where not exists(select 1 from tb2 where classid=t.classid and nameid=t.nameid)
end
CREATE TRIGGER FreightIn ON [dbo].[ordship]
FOR INSERT, UPDATE
AS
insert into Freight (invoice, skuid)
select distinct inv , detilid/10000000 from inserted t
where not exists(select 1 from Freight where invoice=t.inv and skuid=t.detilid/10000000)
create trigger t_collect
on tb1
for insert,update
as
begin
insert into tb2(cid,nid)
select distinct classid/1000 as cid,nameid as nid
from inserteb t
where not exists(select 1 from tb2 where cid=t.classid/1000 and nid=t.nameid)
end