zoukankan      html  css  js  c++  java
  • mysql not null default / default

    not null default 说明不能是NULL, 并设置默认值

    default 设置默认值 , 但值也可能是NULL

    mysql> create table test (id int, name varchar(10) default 'a', addr varchar(10)
     not null default 'b');
    Query OK, 0 rows affected (0.04 sec)
    
    mysql> desc test;
    +-------+-------------+------+-----+---------+-------+
    | Field | Type        | Null | Key | Default | Extra |
    +-------+-------------+------+-----+---------+-------+
    | id    | int(11)     | YES  |     | NULL    |       |
    | name  | varchar(10) | YES  |     | a       |       |
    | addr  | varchar(10) | NO   |     | b       |       |
    +-------+-------------+------+-----+---------+-------+
    3 rows in set (0.00 sec)
    
    mysql> insert into test id values(1);
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
    corresponds to your MariaDB server version for the right syntax to use near 'id
    values(1)' at line 1
    mysql> insert into test id values(1);
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
    corresponds to your MariaDB server version for the right syntax to use near 'id
    values(1)' at line 1
    mysql> insert into test(id) values (1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into test(id) values (1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into test(id) values (1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from test;
    +------+------+------+
    | id   | name | addr |
    +------+------+------+
    |    1 | a    | b    |
    |    1 | a    | b    |
    |    1 | a    | b    |
    +------+------+------+
    3 rows in set (0.00 sec)
    
    mysql> insert into test(id,name) values (1,null);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from test;
    +------+------+------+
    | id   | name | addr |
    +------+------+------+
    |    1 | a    | b    |
    |    1 | a    | b    |
    |    1 | a    | b    |
    |    1 | NULL | b    |
    +------+------+------+
    4 rows in set (0.00 sec)
    
    mysql> insert into test(id,addr) values (1,null);
    ERROR 1048 (23000): Column 'addr' cannot be null
    mysql>
    
  • 相关阅读:
    Dart语言简介
    Flutter简介
    Flutter之环境配置详解for mac版本
    mac 安卓生成证书(uniapp项目安卓证书申请)
    IOS开发者账号申请流程以及开发证书与配置文件的使用
    解读typescript中 super关键字的用法
    解决Vue编译和打包时频繁内存溢出情况CALL_AND_RETRY_LAST Allocation failed
    JS pc端和移动端共同实现复制到剪贴板功能实现
    Web前端接入人机识别验证码---腾讯防水墙
    Unity3D Demo项目开发记录
  • 原文地址:https://www.cnblogs.com/perl6/p/7057616.html
Copyright © 2011-2022 走看看