Get the App
SLTechnology News&Howtos  ›  Database  › 

How to deal with the problem of automatically adding default values in multiple timestamp fields of MySQL

Shulou Source: shulou.com Published: 2022-05-31 15:34:07 10月06日 Update

This article mainly introduces how to deal with the problem of automatically adding default values in multiple timestamp fields of MySQL. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

MySQL version 5.6.14

Construction table sentence

Drop table live_shrimp_info

CREATE TABLE `live_shrimp_ info` (

`LiveID` bigint (20) NOT NULL COMMENT 'live ID'

`SummonStartTime`SummonStartTime` timestamp (3) NOT NULL COMMENT 'call period start time'

`SummonEndTime` timestamp (3) NOT NULL COMMENT 'call period end time'

`CaptureStartTime`CaptureStartTime` timestamp (3) NOT NULL COMMENT 'start time of capture'

`CaptureEndTime`CaptureEndTime` timestamp (3) NOT NULL COMMENT 'end of capture period'

`CreateTime`CreateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time'

`UpdateTime`UPDAT'

PRIMARY KEY (`LiveID`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

After the table is created, use the show create table live_shrimp_info; query

CREATE TABLE `live_shrimp_ info` (

`LiveID` bigint (20) NOT NULL COMMENT 'live ID'

`SummonStartTime`SummonStartTime` timestamp (3) NOT NULL DEFAULT CURRENT_TIMESTAMP (3) ON UPDATE CURRENT_TIMESTAMP (3) COMMENT 'call time'

`SummonEndTime` timestamp (3) NOT NULL DEFAULT '0000-00-

`CaptureStartTime` timestamp (3) NOT NULL DEFAULT '0000

`CaptureEndTime` timestamp (3) NOT NULL DEFAULT '0000

`CreateTime`CreateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time'

`UpdateTime`UPDAT'

PRIMARY KEY (`LiveID`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

What? Why are there so many default values?

That's what's funny about MySQL. It thinks you lack a default value. I added it for you.

The first field of timestamp and not null is automatically added by MySQL.

DEFAULT CURRENT_TIMESTAMP () ON UPDATE CURRENT_TIMESTAMP ()

Other fields of timestamp and not null are automatically added by MySQL.

DEFAULT '0000-00-0000: 00VOV 00'

The above is all the content of this article entitled "how to deal with the problem of automatically adding default values for multiple timestamp fields in MySQL". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Time fields multiple questions content articles updates live broadcasts funny value interests guys buddies that is location more version knowledge industry sentence Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple Xiaomi OPPO Reno NVidia