mysql中TIMESTAMP设置默认值的灵活运用

来源:互联网 发布:软件盒子网站 编辑:程序博客网 时间:2024/06/05 22:54
mysql中TIMESTAMP设置默认值的灵活运用-qhw-ChinaUnix博客 http://blog.chinaunix.net/uid-20577907-id-2213871.html

conclusion:
1.MySQL默认表的第一个timestamp字段为NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP属性,必须显式定义改变这种行为。
2.MySQL只允许一个timestamp字段拥有[DEFAULT CURRENT_TIMESTAMP |ON UPDATE CURRENT_TIMESTAMP]属性。 我的理解为要么都是DEFAULT CURRENT_TIMESTAMP 要么都是DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

3.修改字段属性值

show create table tbl_ledgerrecord;
alter table tbl_ledgerrecord change intoStorageDate  intoStorageDate timestamp DEFAULT CURRENT_TIMESTAMP;