user2063311
user2063311

Reputation: 11

trigger not change data that already exist

I have table just said it Table1, it triggered for insert at Table2, so data from Table1 will inserted into Table2.
The problem is every time data in Table1 changed, data in Table2 from previous trigger changed too.
I want data that already exist from previous trigger still there and not change.

Any solutions?

Here's my code:

create trigger trig_change on Table1
for insert
begin
    insert into Table2
    select * from table1
end

Upvotes: 0

Views: 144

Answers (1)

bijendra
bijendra

Reputation: 36

i'm sure this code must be inserting duplicate values in tab2 .whenever insert event fires on tab1 whole data along with newly inserted row's from tab1 insert into tab2.previously inserted data in tab2 will remain same (that will not be changed while changing in tab1 ). So you need to make some changes inside you code, pls do use defult table (inserted). Here is changed code ,hope this may help you:

 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

Upvotes: 2

Related Questions