[thelist] MySQL - column with default of NOW()

Andrew Forsberg andrew at thepander.co.nz
Fri Mar 8 18:48:00 CST 2002


>in other databases it's legal syntax to set the default value of a column
>to a constant or function that returns the current date and time. this
>would be similar to MySQL's TIMESTAMP data type, except it wouldn't update
>to the current date and time when the row is updated, only when it is
>created without an explicit value.

If it's the first TIMESTAMP column then it should get set to the
current time whenever it's not explicitly stated in an update /
insert, or is NULL, or NOW(). There are a few caveats which you'll
have seen in the docs (e.g., if the update replaces current values
with the same values, then the update is skipped for performance
reasons -- the timestamp won't get updated). Timestamp columns after
the first one have to be set with NULL or NOW() if you want them to
be set to the current time.

>I'd rather not have to explicitly set the field's value to NOW() every
>time if I don't have to. Any ideas? I checked google and mysql.com and i
>gots nuthin.

Try putting the date_modified column before the date_created or any
other date related column.

Oh, and yea: it's bloody annoying! :)

Cheers
Andrew


--
Andrew Forsberg
---
uberNET - http://uber.net.nz/
the pander - http://thepander.co.nz/



More information about the thelist mailing list