문제 설명
열 정의에서 TIMESTAMP 뒤의 값은 무엇을 의미합니까? (What does the value after TIMESTAMP in a column definition mean?)
phpMyAdmin을 통해 몇 개의 MySQL 테이블을 만들었습니다. 그런 다음 테이블 정의에서 일부 TIMESTAMP
열에 값이 첨부되어 있음을 확인했습니다.
timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)
그것이 의미하는 바는 무엇이며 어떤 값을 사용해야 합니까?
참조 솔루션
방법 1:
This syntax is for fractional second precision, see the reference manual:
https://dev.mysql.com/doc/refman/8.0/en/fractional‑seconds.html
MySQL 8.0 has fractional seconds support for TIME, DATETIME, and TIMESTAMP values, with up to microseconds (6 digits) precision
방법 2:
The value after the type defines the fractional seconds part. To quote the documentation:
MySQL 8.0 has fractional seconds support for
TIME
,DATETIME
, andTIMESTAMP
values, with up to microseconds (6 digits) precision:To define a column that includes a fractional seconds part, use the syntax type_name(fsp), where type_name is
TIME
,DATETIME
, orTIMESTAMP
, and fsp is the fractional seconds precision. For example:CREATE TABLE t1 (t TIME(3), dt DATETIME(6));
The fsp value, if given, must be in the range 0 to 6. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0. (This differs from the standard SQL default of 6, for compatibility with previous MySQL versions.)
Therefore, to define a timestamp column with sub‑second precision, you must specify a nonzero value.
(by planetp、Marc Alff、Eugene Yarmash)