MySQL中的datetime与timestamp比较
来源:互联网 发布:最新赚钱软件 编辑:程序博客网 时间:2024/05/16 09:57
相同
显示
TIMESTAMP列的显示格式与DATETIME列相同。换句话说,显示宽度固定在19字符,并且格式为YYYY-MM-DDHH:MM:SS。
不同
范围
datetime
储存
TIMESTAMP
1.4个字节储存(Time stamp value is stored in 4 bytes)
2.值以UTC格式保存( it stores the number of milliseconds)
3.时区转化 ,存储时对当前的时区进行转换,检索时再转换回当前的时区。
datetime
1.8个字节储存(8 bytes storage)
2.实际格式储存(Just stores what you have stored and retrieves the samething which you have stored.)
3.与时区无关(It has nothing to deal with the TIMEZONE andConversion.)
实例对比
现在我来做个时区对他们的影响。
1.先插入一个数据insert into `t8` values(now(), now());
2.改变客户端时区(东9区,日本时区)。
3.再次显示插入的数据,变化了,timestamp类型的数据
接下来 讨论一些timestamp 的其他的属性
1.null 是否为空
timestamp 默认允许为 “非空”(not null by default), 如果你在定义“ts TIMESTAMPDEFAULT NULL” 是非法的。 可以指定为空 null ,“ts TIMESTAMP NULL",这时可以在添加语句改变默认值。
ts2 TIMESTAMP NULL DEFAULT 0,
ts3 TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP
default (一个表中只能有一个列选择下面其中一种)
default CURRENT_TIMESTAMP
default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP
ON UPDATE 见上2
- MySQL中的datetime与timestamp比较
- 【转】MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- mysql中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp比较
- 【整理】MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp区别比较
- MySQL中的datetime与timestamp比较
- MySQL中的datetime与timestamp区别比较
- MySQL中的datetime与timestamp比较
- 利用link标签rel="alternate&…
- js更换样式及cookie设置相关js方法
- Linux scp 使用详解
- 一些疑问留存
- php get_magic_quotes_gpc()…
- MySQL中的datetime与timestamp比较
- Redis pub/sub(Publish,Subsc…
- 如何理解云计算
- Redis的函数---解析
- mysql多条语句执行,仅仅支持mysql…
- c#使用类库编写word插件注意事项
- php的setcookie使用详解
- MySQL 存储php中json_encode…
- PHP5 session 详解【经典】