Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Created Date/Time

Status
Not open for further replies.

lyric0n

Technical User
Dec 28, 2005
74
Hello,
I would like to keep a row in my record that contains information on when the record was created and one when the record was last updated. What is the easiest way to go about doing this in MySQL?

Thanks,
Chris
 
two fields. One a timestamp which will update each time the row is updated or originally inserted (i.e. if never updated).

a second which is datetime which you use now() to insert the date and time when you originally insert your record.
 
Here is what I have tried, but I get errors...

CREATE TABLE splash (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(100),
desc_brief varchar(1024),
posted_dt as date default current_date
rev_dt as datetime on update current_timestamp
);

Any ideas?
 
remove the word "as" (twice)

default values must be constants, so remove DEFAULT CURRENT_DATE

ON UPDATE is intended for foreign keys, so remove that clause too

r937.com | rudy.ca
 
Is there anything that I should add to make sure that the SQL table will automatically insert the proper data and time when a record is inserted/modified?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top