zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    快速排序
    09-HQL:Group、Order
    08-表属性操作
    07-数据导出及动态分区
    06-数据加载
    05-Hive数据操作
    04-表操作2
    03-表操作1
    [原创]IPV4分组的格式
    mysql中having和where的区别
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6200204.html
Copyright © 2011-2022 走看看