MySQL Forums
Forum List  »  Triggers

Re: trigger to create a log file
Posted by: Roland Bouman
Date: February 06, 2006 06:32PM

Did you check out:

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html?

You should be able to find qhat you are looking for. You can also check out thesE:

http://mysql.gilfster.com/page.php?parent_id=2&page_id=2.0.1

To get a quick start:

create trigger air_update
after update on some_table
for each row
begin
if new.forename != old.forname then
insert
into db_log(table_name,event_date,id,user,event_type,field_name,old_value,new_value)
values ('some_table',current_timestamp(),new.id,session_user(),'Update','forename',old.forename,new.forename);
end if;
...
..etc..
..
end;

If you don't fancy writing all the code yourself, user the information_schema (http://dev.mysql.com/doc/refman/5.0/en/information-schema.html) to generate it for you (see
http://mysql.gilfster.com/page.php?parent_id=6&page_id=6.0.2
for such examples)
(BTW, the user that creates the trigger must have the SUPER privilege!)

Options: ReplyQuote


Subject
Views
Written By
Posted
15098
February 06, 2006 04:14AM
Re: trigger to create a log file
7494
February 06, 2006 06:32PM
4078
February 07, 2006 04:15AM
3891
February 07, 2006 05:43AM
3417
February 07, 2006 07:06AM
3405
February 07, 2006 07:22AM
3054
February 07, 2006 10:28AM
3155
February 07, 2006 02:09PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.