understanding triggers to store old db values
716107Oct 24 2010 — edited Oct 26 2010Hi Everyone,
I'm new to triggers and am just trying to understand how to make them work for what I need to do...
Basically I have an application with an associated oracle 10g database. One of the database tables contains information relating to people, and is aptly named 'people'. A single email is stored for each person. When an email address is updated the previous email information is lost. I need to be able to keep this info!
As I have no control over the application, only the database, I'd like to store old email addresses using oracle triggers.
Something like:
CREATE OR REPLACE TRIGGER email_address_log
AFTER UPDATE ON people.email
FOR EACH ROW
WHEN (old.email <> new.email)
BEGIN
old_email_var = old.email
INSERT INTO old_email_addresses (person_id, old_email, date_modified)
VALUES (person_id, old_email_var, SYSDATE);
END;
Although I don't really understand how the trigger gets the person_id value... nor do I understand why this won't compile if I leave out the person id value...
If there's a good tutorial anywhere it would be great if you could point me in the right direction!!!
Thanks!!!