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>

mysql not null default / default的更多相关文章

  1. Mysql 允许null 与 default值

    分为下面4种情况: 1.允许null, 指定default值. 2.允许null, 不指定default,这个时候可认为default值就是null 3.不允许null,指定default值,不能指定 ...

  2. {MySQL完整性约束}一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业

    MySQL完整性约束 阅读目录 一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业 一 ...

  3. mysql 约束条件 not null与default

    not null与default 是否可空,null表示空,非字符串not null - 不可空null - 可空 use db4: 默认值,创建列时可以指定默认值,当插入数据时如果未主动设置,则自动 ...

  4. [MySQL数据库之表的约束条件:primary key、auto_increment、not null与default、unique、foreign key:表与表之间建立关联]

    [MySQL数据库之表的约束条件:primary key.auto_increment.not null与default.unique.foreign key:表与表之间建立关联] 表的约束条件 约束 ...

  5. mysql Alter table设置default的问题,是bug么?

    不用不知道,用了没用? 昨天在线上创建了一个表,其中有两个列是timestamp类型的,创建语句假设是这样的: create table timetest(id int, createtime tim ...

  6. Mysql ERROR 1067: Invalid default value for 字段

    问题: //今天把一个数据库的sql文件导入到另一个数据库出现以下异常: Mysql ERROR 1067: Invalid default value for 字段 //原因是因为之前导出数据里面有 ...

  7. Have You Ever Wondered About the Difference Between NOT NULL and DEFAULT?

    https://blog.jooq.org/2014/11/11/have-you-ever-wondered-about-the-difference-between-not-null-and-de ...

  8. mysql error 1067 invalid default timestamp

    问题 MySQL 5.7版本,在创建数据表时,使用以下语句定义一个字段: `update_time` timestamp DEFAULT '0000-00-00 00:00:00' ON UPDATE ...

  9. Mysql is null 索引

    看到很多网上谈优化mysql的文章,发现很多在谈到mysql的null是不走索引的,在此我觉得很有必要纠正下这类结论.mysql is null是有索引的,而且是很高效的,(版本:mysql5.5)表 ...

随机推荐

  1. 深入学习 Redis系列

    深入学习 Redis(1):Redis 内存模型 深入学习 Redis(2):持久化 深入学习 Redis(3):主从复制 深入学习 Redis(4):哨兵

  2. C#操作access练习

    ORM框架使用dapper,dapper不仅能操作sqlserver,也能操作access,下面为基本代码: OleDbConnection strConnection = new OleDbConn ...

  3. 转:Scipy入门

    Scipy入门 转:http://notes.yeshiwei.com/scipy/getting_started.html 本章节主要内容来自 Getting Started .翻译的其中一部分,并 ...

  4. hadoop 使用Avro求最大值

    在上例中:hadoop MapReduce辅助排序解析,为了求每年的最大数据使用了mapreduce辅助排序的方法. 本例中介绍利用Avro这个序列化框架的mapreduce功能来实现求取最大值.Av ...

  5. 【刷题】BZOJ 1003 [ZJOI2006]物流运输

    Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格 ...

  6. [NOI.AC省选模拟赛3.31] 星辰大海 [半平面交]

    题面 传送门 思路 懒得解释了......也是比较简单的结论 但是自己看到几何就退缩了...... 下周之内写一个计算几何的学习笔记! Code #include<iostream> #i ...

  7. LOJ6276:果树——题解

    https://loj.ac/problem/6276#submit_code NiroBC 姐姐是个活泼的少女,她十分喜欢爬树,而她家门口正好有一棵果树,正好满足了她爬树的需求.这颗果树有N 个节点 ...

  8. UVA.548 Tree(二叉树 DFS)

    UVA.548 Tree(二叉树 DFS) 题意分析 给出一棵树的中序遍历和后序遍历,从所有叶子节点中找到一个使得其到根节点的权值最小.若有多个,输出叶子节点本身权值小的那个节点. 先递归建树,然后D ...

  9. MySQL5.5安装图解

    MySQL5.5安装图解... ====================== 第一部分:去官网下载MySQL安装包... MySQL下载官网:https://dev.mysql.com/downloa ...

  10. [C#] 类型学习笔记二:详解对象之间的比较

    继上一篇对象类型后,这里我们一起探讨相等的判定. 相等判断有关的4个方法 CLR中,和相等有关系的方法有这么4种: (1) 最常见的 == 运算符 (2) Object的静态方法ReferenceEq ...