34,576
社区成员
发帖
与我相关
我的任务
分享
--select 1 --是取第一个字段
--当然也可以用 select * 如下:
where not exists --不存在
(select * from cpfl b where a.th=b.th) --代表b表中与a表中有th相同的记录
where not exists --不存在
(select 1 from cpfl b where a.th=b.th) --代表b表中与a表中有th相同的记录
CREATE TRIGGER [dbo].[tr_scjhb]
ON [dbo].[scjhb]
AFTER INSERT,UPDATE
AS
begin
SET NOCOUNT ON;
INSERT cpfl (th,mc,dw)
SELECT th,mc,dw FROM INSERTED WHERE th IN
(
SELECT th FROM INSERTED
EXCEPT
SELECT th FROM cpfl
)
end
create trigger tri_scjhb
on scjhb
after insert
as
begin
insert into cpfl(th,mc,bz)
select th,mc,bz
from inserted a
where not exists(select 1 from cpfl b where a.th=b.th)
end
CREATE TRIGGER tr_test ON dbo.scjhb
AFTER INSERT
AS
BEGIN
INSERT dbo.cpfl(th,mc,dw)
SELECT DISTINCT th, mc, dw
FROM INSERTED I
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.cpfl M
WHERE i.th = m.th
)
END