Belitho Xavier
Belitho Xavier

Reputation: 139

After Update Trigger SQL

Hey guys i created two tables in oracle sql, first one has 2 columns, and the second has 3 columns(one of them is a foreign key from Pk of first table). I want to create a trigger that AFTER i update the column of the foreign key in second table, will update the other columns according to the value of the pk.

I want to create a trigger that when i update idF(foreign key) in table2 will display the same name as in table1.

Upvotes: 0

Views: 77

Answers (2)

Atif Rizwan
Atif Rizwan

Reputation: 685

you can use this after update trigger on table1

delimiter $$
create trigger MyTrigger after update on table1 
for each row
begin
    update table2 set name = new.name where idF = new.idF;
end$$

Upvotes: 0

Popeye
Popeye

Reputation: 35930

You can create trigger in oracle as follows:

Create or replace trigger trg_table2
Before update of idf on table2
For each row
When (old.idf <> new.idf and new.idf is not null)
Begin
Select name into :new.name 
  from table1
 Where idf = :new.idf;
End;
/

Upvotes: 1

Related Questions