Re: timestamp for update and insert

2007-09-04 Thread Olaf Stein
I would use a trigger (at least for the update) The first insert should work with now() and you can leave lastupdateted empty Olaf On 9/4/07 3:01 PM, Hiep Nguyen [EMAIL PROTECTED] wrote: Hi list, i tried to create a table with inserted lastupdated timestamp fields: create table

Re: timestamp for update and insert

2007-09-04 Thread Michael Dykman
Triggers are a fine idea, but I would use a trigger for both cases.. no point putting that level of housekeeping on the application when you can set rules in the database and more or less forget about it. - michael On 9/4/07, Olaf Stein [EMAIL PROTECTED] wrote: I would use a trigger (at least

Re: timestamp for update and insert

2007-09-04 Thread Olaf Stein
Agreed... Also for consistency's sake On 9/4/07 3:15 PM, Michael Dykman [EMAIL PROTECTED] wrote: Triggers are a fine idea, but I would use a trigger for both cases.. no point putting that level of housekeeping on the application when you can set rules in the database and more or less forget

Re: timestamp for update and insert

2007-09-04 Thread Hiep Nguyen
is it possible to do without trigger? i google and found this link: http://sql-info.de/mysql/examples/CREATE-TABLE-examples.html but when i tried to combine two examples into one CREATE statement and it didn't work. any idea? is there a way to create this table that accomplishes these two

Re: timestamp for update and insert

2007-09-04 Thread Michael Dykman
There is nothing terribly wrong with the approach documented in 'http://sql-info.de/mysql/examples/CREATE-TABLE-examples.html' but, as you no doubt have read, it does mean that you have to make sure that every insert statement is specifically designed to set the *second* timestamp field to now()

RE: timestamp for update and insert

2007-09-04 Thread Daevid Vincent
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

Re: timestamp for update and insert

2007-09-04 Thread Hiep Nguyen
so, if trigger is used then create table temp ( id int not null primary key auto_increment, data varchar(100), inserted timestamp, lastupdated timestamp) is good enough, right? trigger will use now() function to set inserted lastupdated. any thought on backup restore tables tringgers???

Re: timestamp for update and insert

2007-09-04 Thread Olaf Stein
If you decide to use the trigger here is the syntax http://dev.mysql.com/doc/refman/5.0/en/triggers.html And that table structure looks ok to me As far as the backup goes just dump the mysql database, which you should be doing anyway to backup users etc Olaf On 9/4/07 3:59 PM, Hiep Nguyen