The DEFAULT
value clause in a data type specification indicates a default value for a column. The default value must be a constant and cannot be a function or an expression. But for the time type, you can specify the NOW
, CURRENT_TIMESTAMP
, LOCALTIME
, and LOCALTIMESTAMP
functions as the default for TIMESTAMP
and DATETIME
columns.
The BLOB
, TEXT
, and JSON
columns cannot be assigned a default value.
If a column definition includes no explicit DEFAULT
value, TiDB determines the default value as follows:
NULL
as a value, the column is defined with an explicit DEFAULT NULL
clause.NULL
as the value, TiDB defines the column with no explicit DEFAULT
clause.For data entry into a NOT NULL
column that has no explicit DEFAULT
clause, if an INSERT
or REPLACE
statement includes no value for the column, TiDB handles the column according to the SQL mode in effect at the time:
Implicit defaults are defined as follows:
AUTO_INCREMENT
attribute, the default is the next value in the sequence.TIMESTAMP
, the default is the appropriate “zero” value for the type. For TIMESTAMP
, the default value is the current date and time.ENUM
, the default value is the empty string. For ENUM
, the default is the first enumeration value.