mySQL alter table on update, current timestamp

痞子三分冷 提交于 2019-12-24 03:41:10

问题


alter table `quote` 
modify column `timestamp` 
    DEFAULT CURRENT_TIMESTAMP 
    ON UPDATE CURRENT_TIMESTAMP 
    NOT NULL

What's wrong with the above mysql query?

I am trying to change my timestamp column to default and update with the current timestamp.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL' at line 1


回答1:


After MODIFY COLUMN col_name the syntax requires a column_definition which in turn requires a type. Add the current type of this column (e.g. DATETIME) before DEFAULT to resolve the syntax error.




回答2:


This is not so much an answer as it is a tip. In MySQL workbench 6.3 community build, if you want to modify the column using the table edit screen, make certain the "Data Type:" for your timestamp column is for sure set to TIMESTAMP and then make ON UPDATE CURRENT_TIMESTAMP the default value (on my screen, it is just below the "Data Type:").



来源:https://stackoverflow.com/questions/16322557/mysql-alter-table-on-update-current-timestamp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!