List:General Discussion« Previous MessageNext Message »
From:Steve Edberg Date:June 14 2002 2:13pm
Subject:Re: timestamp problem ..
View as plain text  
This is exactly what timestamp columns are supposed to do - see

	http://www.mysql.com/doc/D/A/DATETIME.html

The first timestamp column in the table will be automatically updated 
upon insert/update. Your choices are:

(1) Change to datetime type. Then, on insert, insert the current date 
via now(). It will not be updated unless you specifically change it.

(2) Add a second timestamp column; only the FIRST timestamp column is 
updated as in (1) above. See the docs for mor info.

(3) Keep the column type as timestamp, but always explicitly insert 
the desired date/time - that way, the value won't be automatically 
set. This is probably the least desireable option, though.

If I were me, I'd go with (1). Or, depending on your needs, a 
combination of timestamp & datetime columns.

Now about that beer... ;)

	-steve



At 3:53 PM +0200 6/14/02, Wouter van Vliet wrote:
>Heey Folks,
>
>I'm having a slight problem with the timestamp column format. When I alter a
>table and, add a column of type timestamp all records get the current
>timestamp, that's ok. When i insert a new row, all records get the current
>timestamp. That too is ok. But now, when I update one row of the table, that
>row gets a new timestamp. And that's not what i'd like it to do. Does
>somebody have any idea on how this can be prevented?
>
>I've tried to make the column of type int(14) and then set now() or
>UNIX_TIMESTAMP as default value, but that just results in a very well known
>error 1064 (You have an error in your SQL syntax near 'NOW()' at line 1).
>
>Thanks !
>Wouter
>
>(ps. beer for the helper .. if you'd come up with some idea to give it to
>you)
>


-- 
+------------------------------------------------------------------------+
| Steve Edberg                                      sbedberg@stripped |
| University of California, Davis                          (530)754-9127 |
| Programming/Database/SysAdmin               http://pgfsun.ucdavis.edu/ |
+------------------------------------------------------------------------+
| "If only life would imitate toys."                                     |
|                  - Ted Raimi, March 2002                               |
|                  - http://www.whoosh.org/issue67/friends67a.html#raimi |
+------------------------------------------------------------------------+
Thread
Create database in other location ...Silmara Cristina Basso14 Jun
  • timestamp problem ..Wouter van Vliet14 Jun
    • Re: timestamp problem ..Victoria Reznichenko14 Jun
    • Re: timestamp problem ..Steve Edberg14 Jun
  • Re: Create database in other location ...Egor Egorov14 Jun
RE: timestamp problem ..Luc Foisy14 Jun
  • RE: timestamp problem ..Wouter van Vliet14 Jun
  • Re: timestamp problem ..Chuck Amadi17 Jun