What I want to do, is that I'd like to change the column properties, and associate a default value for a certain column, and this value would be from a sub-query. Basically the default value of timeOfCreation should be a subquery--> (select NOW()).But for some reason it returns a syntax error, which I don't understand. Here's my command, which I input.
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
ALTER TABLE `horizon`.`articles` CHANGE COLUMN `timeOfCreation` `timeOfCreation` DATETIME NULL DEFAULT (select NOW()) ;
SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
And the error:
Executing SQL script in server
ERROR: Error 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 '(select NOW())' at line 1
ALTER TABLE `horizon`.`articles` CHANGE COLUMN `timeOfCreation` `timeOfCreation` DATETIME NULL DEFAULT (select NOW())
SQL script execution finished: statements: 3 succeeded, 1 failed
Ps. I'm using workbench as a software, but I don't think it would matter.