|
|
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?
|
|
0
|
|
|
|
Reply
|
lawpoop
|
11/27/2007 6:01:13 PM |
|
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
|
|
0
|
|
|
|
Reply
|
Paul
|
11/27/2007 7:14:30 PM
|
|
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
|
|
0
|
|
|
|
Reply
|
Peter
|
11/28/2007 3:45:35 PM
|
|
|
2 Replies
861 Views
(page loaded in 0.046 seconds)
|
|
|
|
|
|
|
|
|