MySQL-设置时间默认值和随update sql更新而自动更新时间-DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRE
建表语句
CREATE TABLE `time_sql_test` (
`id` int(10) unsigned zerofill NOT NULL AUTO_INCREMENT,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`test_value` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
Navicat中查看建语句:
1 选中表,
2 鼠标右击
3 选择对象信息
4 然后选择DDL
--------------------------------------------------------------------------------
SELECT * from time_sql_test;
ALTER TABLE time_sql_test MODIFY create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ;
ALTER TABLE time_sql_test MODIFY update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ;
insert time_sql_test(test_value) VALUES('test_values_1')
SELECT * from time_sql_test;
update time_sql_test set test_value='test_values_2' where id=1;
SELECT * from time_sql_test;
另外也可以通过Navicat设置time的默认值和更新属性,记录Ctrl+S保存一下
--------------------------------------------------------------------------------
正文到此结束