SEE: Update timestamp column in Application or Database?
I'm trying to model something similar in Workbench, but I don't know where to set the "ON UPDATE" part. The best I can get is the following:
-- -----------------------------------------------------
-- Table `foo`.`test`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `foo`.`test` ;
CREATE TABLE IF NOT EXISTS `foo`.`test` (
`test_id` INT NOT NULL ,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`date_updated` TIMESTAMP NOT NULL DEFAULT 0 ,
PRIMARY KEY (`test_id`) )
ENGINE = InnoDB;
Where do I go in Workbench to set up this ON UPDATE part?
Also, I have a rule that all timestamps stored in the database should be UTC. How do I make CURRENT_TIMESTAMP, NOW, etc. be UTC?
I am using MySQL Workbench 5.2.35. Open create/alter table panel, switch to the columns tab, right click on the timestamp field; there you can see possible default
and on update
options.
Important note: You can use CURRENT_TIMESTAMP
as default or updated value for only a single column in a table!
Regarding the UTC question, you can have a look at this question. There is an accepted solution there.
I would suggest you to read MySQL reference manuals as well for Timestamp data type and NOW()
function.