MySQL: Is there a way to automatically set datetime field to record creation timestamp?

Use a trigger to set the default. DELIMITER | CREATE TRIGGER trigger_name BEFORE INSERT ON tbl_name FOR EACH ROW BEGIN SET NEW. Colname = NOW(); END; | Try this one, including the delimiter.

I vote up. Yet, it's not really a complete answer... – tishma Dec 11 '10 at 16:28 Thanks for the edit. I'll accept it.

Btw, PHPMyAdmin will have problem with this statement, because of ";" that's used as a statement delimiter. – tishma Dec 11 '10 at 16:45.

I'd like to have a column that automatically populates to NOW() (or CURRENT_TIMESTAMP) and never changes By saying you'd like it to populate to NOW() it sounds like you're referring to the initial INSERT. If that's the case, can you just use that? Something like INSERT INTO table (field1,field2,my_datetime) VALUES (1,'a',NOW()).

Exactly. Only this is not quite automatic... I'd like to never mention that column in INSERT statements. – tishma Dec 11 '10 at 16:34 Now way I know of then -- I'd lean towards the trigger.

– Riedsio Dec 11 '10 at 16:37 I guess I'll accept trigger. However, I'm stuck with this MySQL version, and creating a trigger requires SUPER privilege, so it doesn't really work for me :( – tishma Dec 11 '10 at 16:42 You need TRIGGER privileges: dev.mysql. Com/doc/refman/5.5/en/… – Frank Heikens Dec 11 '10 at 16:53.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions