Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

MySQL - valor padrão para TIMESTAMP(3)


Conforme documentação em timestamp e datetime tipo colunas:

Outros exemplos :
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)

Consulte :
Inicialização e Atualizando para TIMESTAMP e DATETIME