If you are using 4.1.2 or later, you can define the default and update behavior separately for TIMESTAMP columns with the DEFAULT and ON UPDATE clauses.

 CREATE TABLE t (ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, ...

In this example, column ts will be set to now on creation (INSERT) because of the DEFAULT, but will remain unchanged on update, because ON UPDATE was not specified. This is explained in the third page of the manual Jigal referenced.

Prior to 4.1.2, you will need to use a DATETIME column, as Jigal suggested, which you will have to explicitly set to NOW() on creation.

Michael

Jigal van Hemert wrote:
i would like to create a Timestamp upon initial creation of a record. I
expected this could be done using now() in my INSERT statement but obv.

the

related field gets actualised each time a record is updated. Unfortunately
that's not what i like - i would like to have the timestamp set just once
upon creation time without any changes later on.
How could this be done?


Frank,

Use a datetime field instead, as it is not updated automagically.

More about date and time column types:
http://dev.mysql.com/doc/mysql/en/Date_and_time_types.html

And more about timestamp behaviour prior to version 4.1:
http://dev.mysql.com/doc/mysql/en/TIMESTAMP_pre-4.1.html
and the behaviour in version 4.1 or later:
http://dev.mysql.com/doc/mysql/en/TIMESTAMP_4.1.html

Regards, Jigal.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to