Link to home
Start Free TrialLog in
Avatar of jamie_lynn
jamie_lynn

asked on

Trigger date

Hi,
I'm trying to create a trigger in mysql 4.1.9 to insert the date automatically to my date_created field when the row is created or updated.
I would use this statement below if my database was oracle. How can I do this in mysql?

Thanks
Jamie

CREATE TABLE user (
      username varchar(100) not null,
      date_created datetime not null,
      PRIMARY KEY (username)
)

CREATE OR REPLACE TRIGGER user_date_created_tr
BEFORE
INSERT OR
UPDATE
ON user
FOR EACH ROW
BEGIN
      :new.date_created := sysdate;
END;
SOLUTION
Avatar of Yuval_Shohat
Yuval_Shohat
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jamie_lynn
jamie_lynn

ASKER

Cool. Thanks everyone!
Jamie
But- are you sure that you want change date_created after UPDATE?