Unix Technical Forum

automatic creation and last modification timestamps in table?

This is a discussion on automatic creation and last modification timestamps in table? within the MySQL forums, part of the Database Server Software category; --> Hello all - I would like to have a table with a column that shows me the timestamp of ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:30 AM
lawpoop@gmail.com
 
Posts: n/a
Default automatic creation and last modification timestamps in table?

Hello all -

I would like to have a table with a column that shows me the timestamp
of when the row was inserted, and another column of when the row was
last updated. Ideally, these values would fill in automatically on
INSERTs and UPDATEs.

I was looking at the MySQL timestamp column properties for 5.0, and it
looks like what I want is impossible. It seems that only one timestamp
column in a table can have an automatically set timestamp.

CREATE TABLE `guestrak`.`timestamp_test` (
`id` INT UNSIGNED NOT NULL ,
`modification` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL ,
`creation` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( `id` )
) ENGINE = InnoDB

MySQL said: Documentation
#1293 - Incorrect table definition; there can be only one TIMESTAMP
column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

[output from phpMyAdmin]

So, that means that I would have to set the value for the creation
timestamp column manually, and then use an automated column for the
modification timestamp.

Is that correct?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:30 AM
Paul Lautman
 
Posts: n/a
Default Re: automatic creation and last modification timestamps in table?

lawpoop@gmail.com wrote:
> Hello all -
>
> I would like to have a table with a column that shows me the timestamp
> of when the row was inserted, and another column of when the row was
> last updated. Ideally, these values would fill in automatically on
> INSERTs and UPDATEs.
>
> I was looking at the MySQL timestamp column properties for 5.0, and it
> looks like what I want is impossible. It seems that only one timestamp
> column in a table can have an automatically set timestamp.
>
> CREATE TABLE `guestrak`.`timestamp_test` (
> `id` INT UNSIGNED NOT NULL ,
> `modification` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL ,
> `creation` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
> PRIMARY KEY ( `id` )
> ) ENGINE = InnoDB
>
> MySQL said: Documentation
> #1293 - Incorrect table definition; there can be only one TIMESTAMP
> column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
>
> [output from phpMyAdmin]
>
> So, that means that I would have to set the value for the creation
> timestamp column manually, and then use an automated column for the
> modification timestamp.
>
> Is that correct?


Sounds like it to me


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:30 AM
Peter H. Coffin
 
Posts: n/a
Default Re: automatic creation and last modification timestamps in table?

On Tue, 27 Nov 2007 10:01:13 -0800 (PST), lawpoop@gmail.com wrote:
> So, that means that I would have to set the value for the creation
> timestamp column manually, and then use an automated column for the
> modification timestamp.
>
> Is that correct?


Yup. NOW() is your friend for that insert.

--
99. Any data file of crucial importance will be padded to 1.45Mb in size.
--Peter Anspach's list of things to do as an Evil Overlord
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:05 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com