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

Howard Cheng howcheng at ix.netcom.com
Fri Mar 8 19:11:01 CST 2002


I don't know of a way to do this in MySQL except by using the TIMESTAMP
data type. On update, you would have to explicitly set the timestamp field
to be equal to itself so that it doesn't change.

UPDATE mytable SET a=1, b=2, c=3, timestampfield=timestampfield where id=...


At 07:31 PM 3/8/2002 -0500, Warden, Matt wrote:
>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.
>
>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.

::::::::::::::::::::::
Howard Cheng
howcheng at ix.netcom.com
AIM: bennyphoebe
ICQ: 47319315




More information about the thelist mailing list