Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default Current _Timestamp on update Current_Timestamp

Status
Not open for further replies.

vacunita

Programmer
Aug 2, 2001
9,166
MX
I'm getting an error, when I try to create a new table.
Code:
 CREATE TABLE `comments` (
`id_coment` int( 11 ) NOT NULL AUTO_INCREMENT ,
`n_person` varchar( 50 ) default NULL ,
`email` varchar( 100 ) default NULL ,
`comen` text,
`place` varchar( 20 ) default NULL ,
`comment_date` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
PRIMARY KEY ( 'id_coment' )
)
And I'm getting this error:
Code:
You have an error in your SQL syntax near 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY ('id_coment')' at line 7

Any ideas why?
Note: The query has no problems locally. When I try to run it through PHPmyAdmin on my webhost it comes back with this error.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
The text "PRIMARY KEY ('id_coment')" should use backticks instead of quotes. Other than that, it should work, though I don't use PHPMyAdmin.
 
Thanx tony, but even with the backticks it still kicks back the error.

If I remove the [red]CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,[/red] from thr statement it works.
like so:
Code:
CREATE TABLE `comments` (
...  
`fecha` timestamp NOT NULL default 0, 
  PRIMARY KEY  (`id_comentario`)
)
[code]

There is something about the [red]CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,[/red] part that mysql doesn't like.

But I'm puzzled as to what it could be.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Yeah, I think that might be it.

So i took out the CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP part.

The server still assigns the current timestamp as the default value for the field so it works.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
If you do a
Code:
select version()
you can find out what version you are running of course.
 
Yeah I know, I did after my post and found out its 3.23. something. Pretty Ld, I'll have to watch out with any further table creations.

Alsi i sent the webhost An email and asked them to update their mysql server. No answer as of yet.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top