http://jasonbos.co/two-timestamp-columns-in-mysql/
这是一个非常常见的表:有create_time , update_time,甚至可以说是规范,当然我们想这些时间自动更新,交给Mysql处理,但是问题来了:
创建一个这样的表:
CREATE TABLE `test_table` ( `id` INT( 10 ) NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE = INNODB;
原来Mysql会自动处理:
CREATE TABLE `test_table` ( `id` INT( 10 ) NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT 0, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE = INNODB;
INSERT INTO test_table (id, created_at, updated_at) VALUES (1, NULL, NULL);
have fun...
原文:http://my.oschina.net/ifeixiang/blog/425012