Afficher un message
Vieux 04/09/2007, 20h55   #7
Daevid Vincent
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: timestamp for update and insert

Just do this...

create table temp (
id int not null primary key auto_increment,
data varchar(100),
inserted timestamp default 0,
lastupdated default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

And just use

Insert into temp (inserted ) values (NOW());

You're only inserting once, so just do it in the code.

Then no need for triggers -- what a waste. Mysql will update the lastupdated
field.

Note the 'default 0' that is important... When you have multiple timestamp
columns and want one to be auto handled.

D.Vin

> -----Original Message-----
> From: Hiep Nguyen [mailto:hiep@ee.ucr.edu]
> Sent: Tuesday, September 04, 2007 12:02 PM
> To: mysql@lists.mysql.com
> Subject: timestamp for update and insert
>
> Hi list,
>
> i tried to create a table with inserted & lastupdated
> timestamp fields:
>
> create table temp (
> id int not null primary ke auto_increment,
> data varchar(100),
> inserted timestamp default now(),
> lastupdated timestamp(8));
>
>
> how do i get mysql to put in the current timestamp for inserted &
> lastupdated fields when i insert a record and only lastupdated when i
> update the record?
>
> thanks,
> T. Hiep
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=daevid@daevid.com
>
>


  Réponse avec citation
 
Page generated in 0,05596 seconds with 9 queries