Is there any way, in MySQL, to dynamically generate a field value? For example a field that stamps the exact date and time that a row was inserted.
You could just get the interface to do it (i.e. PHP) but in a case where you have more than one handler it would be safer if I could get MySQL to do it independently.
The MySQL
TIMESTAMPdata type has a special default calledCURRENT_TIMESTAMPthat does this.Read all about it:
http://dev.mysql.com/doc/refman/5.1/en/timestamp.html
EDIT:
For the more generic case, use a trigger. You can set the value on an insert using a
BEFORE INSERTtriggers, and likewise you can set the value on updates using a separateBEFORE UPDATEtrigger:http://dev.mysql.com/doc/refman/5.1/en/create-trigger.html