高手帮忙看一下这个触发器吧???
create trigger ti_a on 车辆基础档案
for insert
as
if not exists(select 1 from bh_车辆变化,inserted i where bh_车辆变化.车辆id=i.id)
begin
insert into bh_车辆变化(车辆id)
select id
From 车辆基础档案 A
Inner Join bh_车辆变化 B On A.ID = B.车辆id
Inserted C On A.id = C.车辆id
END
看不出有什么错??
具体要求:就是如果车辆基础档案中有插入的记录,那么就把插入后生成的ID插入到
BH_车辆变化 表中。
------解决方案--------------------create trigger ti_a on 车辆基础档案
for insert
as
if not exists(select 1 from bh_车辆变化,inserted i where bh_车辆变化.车辆id=i.id)
begin
insert into bh_车辆变化(车辆id)
select
id
From
车辆基础档案 A,
bh_车辆变化 B,
Inserted C
where
A.ID = B.车辆id and A.id = C.车辆id
END
------解决方案--------------------create trigger ti_a on 车辆基础档案
for insert
as
insert bh_车辆变化(车辆id)
select id from inserted where id not in(select id from bh_车辆变化)