MySQL-TIMESTAMP(3)的默认值

MySQL-TIMESTAMP(3)的默认值,第1张

MySQL-TIMESTAMP(3)的默认值

根据文档

timestamp
datetime
输入列:

如果

TIMESTAMP
DATETIME
定义在任何地方都包含显式的小数秒精度值,则在整个列定义中必须使用相同的值。

这是允许的:

CREATE TABLE t1 (  ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE

CURRENT_TIMESTAMP(6)
);


其他例子

mysql> create table tbl_so_q23671222_1( ts timestamp(3) default now() );ERROR 1067 (42000): Invalid default value for 'ts'mysql> create table tbl_so_q23671222_1( ts timestamp(3) default now(3) );Query OK, 0 rows affected (0.59 sec)mysql> create table tbl_so_q23671222_2( ts timestamp(3) default current_timestamp );ERROR 1067 (42000): Invalid default value for 'ts'mysql> create table tbl_so_q23671222_2( ts timestamp(3) default current_timestamp(3) );Query OK, 0 rows affected (0.38 sec)mysql> desc tbl_so_q23671222_1;+-------+--------------+------+-----+----------------------+-------+| Field | Type         | Null | Key | Default   | Extra |+-------+--------------+------+-----+----------------------+-------+| ts    | timestamp(3) | NO   |     | CURRENT_TIMESTAMP(3) |       |+-------+--------------+------+-----+----------------------+-------+1 row in set (0.01 sec)mysql> desc tbl_so_q23671222_2;+-------+--------------+------+-----+----------------------+-------+| Field | Type         | Null | Key | Default   | Extra |+-------+--------------+------+-----+----------------------+-------+| ts    | timestamp(3) | NO   |     | CURRENT_TIMESTAMP(3) |       |+-------+--------------+------+-----+----------------------+-------+1 row in set (0.01 sec)

请参阅
TIMESTAMP和DATETIME的初始化和更新



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/4962199.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存