Environment
MySQL 5.1 + command line tools
Problem
MySQL table field Set default value
Solve
--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 is not valid--time_d time is not
null default Curtime (),
--date_e date is not null default Curdate (),
--datetime_ f datetime not NULL DEFAULT now (),
Summarize
int type: The default value must also be an integral type, and no () bracket behind default.
Char type: The default value is to use single quotes.
DateTime type: the Now () function returns the current date time with ' Yyyy-mm-dd HH:MM:SS ', and can be saved directly to the DateTime field. Using system defaults is not supported.
Date type: Curdate () returns today's date in ' YYYY-MM-DD ' format and can be stored directly in the Date field. Using system defaults is not supported.
Time Type: Curtime () returns the current period in ' HH:MM:SS ' format, which can be stored directly in the Duration field. Using system defaults is not supported.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/MySQL/