I know there is TIMESTAMP data type that automatically updates to timestamp value when a record is updated, and I already have such column.
Besides that I'd like to have a column that automatically populates to NOW() (or CURRENT_TIMESTAMP) and never changes, but MySQL DEFAULT doesn't appear to support function calls.
Please post only pure MySQL answers. I know how to do it at application level.
EDIT: If there's no such feature - I'd appreciate to hear that.
EDIT2: MySQL version is 5.0.32
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With