我有表刚刚说它Table1,它触发了在Table2的插入,所以来自Table1的数据将插入到Table2中。
问题是每次表 1 中的数据发生变化时,表 2 中来自先前触发器的数据也发生了变化。
我希望先前触发器中已经存在的数据仍然存在并且不会改变。
有什么解决办法吗?
这是我的代码:
create trigger trig_change on Table1
for insert
begin
insert into Table2
select * from table1
end
我有表刚刚说它Table1,它触发了在Table2的插入,所以来自Table1的数据将插入到Table2中。
问题是每次表 1 中的数据发生变化时,表 2 中来自先前触发器的数据也发生了变化。
我希望先前触发器中已经存在的数据仍然存在并且不会改变。
有什么解决办法吗?
这是我的代码:
create trigger trig_change on Table1
for insert
begin
insert into Table2
select * from table1
end
我确定这段代码必须在 tab2 中插入重复值。每当插入事件触发 tab1 整个数据以及从 tab1 插入到 tab2 的新插入行时。tab2 中先前插入的数据将保持不变(在更改时不会更改表 1)。因此,您需要在代码中进行一些更改,请务必使用默认表(插入)。这是更改的代码,希望这可以帮助您:
create trigger trig_change on Table1
for insert
begin
insert into Table2
select a.* from table1 a,inserted i
where a.col1=i.col1
end