问题
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