Click to See Complete Forum and Search --> : Current Date & Update in a table issue on table creation


\\.\
01-15-2008, 12:23 PM
How do you create a table with a DATETIME field that will inset the current date and time on creation of a record and on each update to the record?

I have tried `visit` DATETIME DEFAULT TIMESTAMP ON UPDATE TIMESTAMP NOT NULL , but it says that this is wrong, so I tried `visit` DATETIME DEFAULT DATETIME ON UPDATE DATETIME NOT NULL , and it says that is wrong.

the full query I am issuing in the server is...
CREATE TABLE `member`.`reg` (
`id` MEDIUMINT( 8 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`visit` DATETIME DEFAULT TIMESTAMP ON UPDATE TIMESTAMP NOT NULL ,
`login` TINYINT( 1 ) DEFAULT 0 NOT NULL
) ENGINE = MYISAM

What I need to do is have the table reg to automatically update the specific members state to show that last time they visited the site, as well as insert the current date when the record is made, PHP will be used to update the table but I need the server to auto insert the date & time stamp as required on creation or on update of the record.

What is the correct syntax please as searching the SQL section gives no clues.

Thx.

chazzy
01-15-2008, 06:58 PM
it looks like you're using mysql. what version of mysql?

\\.\
01-15-2008, 09:36 PM
Not sure as its on a web host.

chazzy
01-15-2008, 10:51 PM
well if it's 5.0 or higher, you can use teh default value for the column as NOW().

If it's not... well, you can't then, it has to be programmatically.

http://dev.mysql.com/doc/refman/5.0/en/create-table.html

\\.\
06-14-2008, 07:38 AM
Thanks for the input, I will investigate this when I need it as we have gone in a different development direction because of a domain name change and our current development has ceased until the change takes place.