When I create a new table
create table test(rId int auto_increment, createtimestamp timestamp not null, PRIMARY KEY (rId));
it creates a table with default schema for createtimestamp
as CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
.
Expected behavior was no default set. But it's getting set to default: CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
. Why is this happening?
I can alter this after the creation with ALTER TABLE test CHANGE COLUMN createtimestamp createtimestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;
but can't alter it to ALTER TABLE test CHANGE COLUMN createtimestamp createtimestamp TIMESTAMP NOT NULL ;
.
It looks like a default has to be specified but this is exactly what I don't want. How can I achieve a behavior where the default is not set and schema is not null, just after creation of table and without any alteration required?
MySql Version: 5.5.49
初始答案是正确的,但如果在定义中有一个默认值或NULL是不可接受的,那么可以考虑使用datetime,或者升级到允许行为更改的MySQL 5.6 http://dev.mysql.com/doc /refman/5.6/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.