Environment
MySQL 5.1 + command line tool
Problem
MySQL table field settings Default Value
Solution
-- SQL:
Create table test (
I _a int NOT NULL DEFAULT 1,
Ts_ B timestamp NOT NULL DEFAULT NOW (),
C_c char (2) not null default '1'
);
-- The following SQL statements are invalid.
-- Time_d time not null default curtime (),
-- Date_e date not null default curdate (),
-- Datetime_f datetime not null default now (),
Summary
Int type: the default value must also be an integer, and no brackets () are left behind the default value.
Char type: single quotes are used by default.
DATETIME type: NOW () function returns the current date and time with 'yyyy-MM-DD HH: MM: ss', which can be saved directly to the DATETIME field. Default values are not supported.
DATE type: CURDATE () returns today's DATE in 'yyyy-MM-DD 'format and can be saved directly to the DATE field. Default values are not supported.
TIME type: CURTIME () returns the current TIME in 'hh: MM: ss' format and can be saved directly to the TIME field. Default values are not supported.
References
Functions used by MySQL to obtain the current system time