您好,欢迎访问一九零五行业门户网

MYSQL中TIMESTAMP类型的默认值

欢迎进入linux社区论坛,与200万技术人员互动交流 >>进入 mysql中timestamp类型的默认值 mysql中timestamp类型可以设定默认值,就像其他类型一样。 1、自动update 和insert 到当前的时间:表:―――――――――――table create table―― ―――――――
欢迎进入linux社区论坛,与200万技术人员互动交流 >>进入
mysql中timestamp类型的默认值
mysql中timestamp类型可以设定默认值,就像其他类型一样。
1、自动update 和insert 到当前的时间:表:―――――――――――table   create table―― ――――――――――――――――――――――――――――- t1      create table `t1` (`p_c` int(11) not null,`p_time` timestamp not null default current_timestamp on update current_timestamp) engine=innodb default charset=gb2312数据:1    2007-10-08 11:53:35 2    2007-10-08 11:54:00 insert into t1(p_c) select 3;update t1 set p_c = 2 where p_c = 5;数据:1    2007-10-08 11:53:35 5    2007-10-08 12:00:37 3    2007-10-08 12:00:37 2、自动insert 到当前时间,不过不自动update.表:―――――――――――table   create table―― ―――――――――――――――――――t1      create table `t2` (`p_c` int(11) not null,`p_time` timestamp not null default current_timestamp) engine=innodb default charset=gb2312数据:insert into t2(p_c) select 4;update t2 set p_c = 3 where p_c = 5;1    2007-10-08 11:53:35 2    2007-10-08 12:00:37 5    2007-10-08 12:00:37 4    2007-10-08 12:05:19 3、一个表中不能有两个字段默认值是当前时间,否则就会出错。不过其他的可以。
表:―――――――――――table   create table―― ―――――――――――――――――――――t1      create table `t1` (`p_c` int(11) not null,`p_time` timestamp not null default current_timestamp,`p_timew2` timestamp not null default '0000-00-00 00:00:00') engine=innodb default charset=gb2312数据:1    2007-10-08 11:53:35    0000-00-00 00:00:00 2    2007-10-08 12:00:37    0000-00-00 00:00:00 3    2007-10-08 12:00:37    0000-00-00 00:00:00 4    2007-10-08 12:05:19    0000-00-00 00:00:00 timestamp的变体1,timestamp default current_timestamp on update current_timestamp在创建新记录和修改现有记录的时候都对这个数据列刷新
2,timestamp default current_timestamp在创建新记录的时候把这个字段设置为当前时间,但以后修改时,不再刷新它
3,timestamp on update current_timestamp在创建新记录的时候把这个字段设置为0,以后修改时刷新它
4,timestamp default ‘yyyy-mm-dd hh:mm:ss’ on update current_timestamp在创建新记录的时候把这个字段设置为给定值,以后修改时刷新它
其它类似信息

推荐信息