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:[EMAIL PROTECTED] 
> 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/[EMAIL PROTECTED]
> 
> 


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

Reply via email to