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;
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
But- are you sure that you want change date_created after UPDATE?
ASKER
Jamie