Hi
Is it possible to use a trigger on a table to update a different table using parameters?
TableA
user | id | data | duration
10 1 aaa 200
TableB
user | id | totDuration
10 1 null
What I am trying to do is to have a trigger on TableA when an UPDATE takes place to update totDuration column in TableB. I will try to explain using a trigger creation that obviously do not work but maybe you can see what I am trying to do.
create trigger trigger_name after update on TableA
for each row
begin
declare @user integer;
declare @id integer;
set @user = [user from TableA]
set @id = [id from TableA]
update TableB
set duration=duration + [duration from TableA]
where
user=@user
and id=@id
end
What I should end up with in the duration column in TableB is 200. If I do another update with the same value I should end up with 400 and so forth.
I am using Mysql 5.0.2
Thank you
/M
Is it possible to use a trigger on a table to update a different table using parameters?
TableA
user | id | data | duration
10 1 aaa 200
TableB
user | id | totDuration
10 1 null
What I am trying to do is to have a trigger on TableA when an UPDATE takes place to update totDuration column in TableB. I will try to explain using a trigger creation that obviously do not work but maybe you can see what I am trying to do.
create trigger trigger_name after update on TableA
for each row
begin
declare @user integer;
declare @id integer;
set @user = [user from TableA]
set @id = [id from TableA]
update TableB
set duration=duration + [duration from TableA]
where
user=@user
and id=@id
end
What I should end up with in the duration column in TableB is 200. If I do another update with the same value I should end up with 400 and so forth.
I am using Mysql 5.0.2
Thank you
/M