Welcome to the Linux community forum and interact with 2 million technical staff to enter the default value of TIMESTAMP type in MYSQL. You can set the default value for TIMESTAMP type in MYSQL, just like other types. 1. Automatic UPDATE and INSERT to the current time: Table: --- TableCreateTable ―――――――――
Welcome to the Linux community forum and interact with 2 million technical staff> enter the default value of TIMESTAMP type in MYSQL. You can set the default value of TIMESTAMP type in MYSQL, just like other types. 1. Automatic UPDATE and INSERT to the current time: Table: --- Table Create Table ―――――――――
Welcome to the Linux community forum and interact with 2 million technicians>
Default Value of TIMESTAMP type in MYSQL
You can set the default value for the TIMESTAMP type in MYSQL, just like other types.
1. Automatic UPDATE and INSERT to current time: Table: -- 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 data: 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; Data: 1 11:53:35 5- 08 12:00:37 3 2007-10-08 12:00:37 2. Automatic INSERT to current time, but not automatic UPDATE. table: -- 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 data: 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 1 2:05:19. A table cannot have two fields. The default value is the current time. Otherwise, an error occurs. But others can.
Table: -- 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 '2017-00-00 00:00:00 ') ENGINE = InnoDB default charset = gb2312 data: 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 Variant 1, timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP refresh this data column when creating a new record and modifying an existing record
2, timestamp default CURRENT_TIMESTAMP when creating a new record, set this field to the current time, but will not refresh it later
3. timestamp on update CURRENT_TIMESTAMP: set this field to 0 when creating a new record, and refresh it later.
4, timestamp default 'yyyy-mm-dd hh: mm: ss' on update CURRENT_TIMESTAMP set this field to a given value when creating a new record, and refresh it later when it is modified.