mysql null值问题

mysql>   create table test( sn int,
    ->   `createdTime` datetime NOT NULL COMMENT '创建时间',
    ->   `updatedTime` datetime DEFAULT NULL);
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1199508
Current database: devops

Query OK, 0 rows affected (0.04 sec)

mysql> desc test;
+-------------+----------+------+-----+---------+-------+
| Field       | Type     | Null | Key | Default | Extra |
+-------------+----------+------+-----+---------+-------+
| sn          | int(11)  | YES  |     | NULL    |       |
| createdTime | datetime | NO   |     | NULL    |       |
| updatedTime | datetime | YES  |     | NULL    |       |
+-------------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> insert into test values('1',null,null);
ERROR 1048 (23000): Column 'createdTime' cannot be null


mysql> insert into test values('1','2015-01-01 00:00:00',null);
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+------+---------------------+-------------+
| sn   | createdTime         | updatedTime |
+------+---------------------+-------------+
|    1 | 2015-01-01 00:00:00 | NULL        |
+------+---------------------+-------------+
1 row in set (0.00 sec)



mysql> alter table `test` modify column `updatedTime` datetime NOT NULL COMMENT '更新时间';
ERROR 1138 (22004): Invalid use of NULL value

posted @ 2016-04-06 09:30  czcb  阅读(198)  评论(0编辑  收藏  举报