MySQL字段默认值设置详解

复制# 格式模板 <字段名> <数据类型> DEFAULT <默认值> # 示例 mysql> CREATETABLE `test_tb` ( -> `id` intNOTNULL AUTO_INCREMENT,段默 -> `col1` varchar(50) notnullDEFAULTa, -> `col2` intnotnullDEFAULT 1, -> PRIMARYKEY (`id`) -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.06 sec) mysql> desc test_tb; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | col1 | varchar(50) | NO | | a | | | col2 | int(11) | NO | | 1 | | +-------+-------------+------+-----+---------+----------------+ 3 rowsinset (0.00 sec) mysql> insertinto test_tb (col1) values (fdg); Query OK, 1 row affected (0.01 sec) mysql> insertinto test_tb (col2) values (2); Query OK, 1 row affected (0.03 sec) mysql> select * from test_tb; +----+------+------+ | id | col1 | col2 | +----+------+------+ | 1 | fdg | 1 | | 2 | a | 2 | +----+------+------+ 2 rowsinset (0.00 sec) 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.