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. struts如何在Action类中操作request,session

    在servlet中,通过request.getparameter与setparameter来实现后端与前端jsp页面的数据交互,那么在struts中,也有几种方式来操作request,session实 ...

  2. Redis 学习之集群

    该文使用centos6.5 64位  redis3.2.8 一.  redis-cluster架构图 集群通信:所有redis节点之间通过PING-PONG机制彼此互联,内部使用二进制鞋子优化传输速度 ...

  3. vmware 虚拟机下安装centOS7.0

    当时安装的是 CentOS-7.0-1406-x86_64-DVD.iso 这个版本的镜像,提示: 您已经配置此虚拟机使用64位客户操作系统.但是64位操作系统不可用.此主机具有虚拟化支持能力的,可是 ...

  4. 【Python】python基础_代码编写注意事项

    1. 说明使用的编译方式 1 #!/usr/bin/python 2. 说明字符编码方式 1 #coding=utf-8 3. print 默认输出是换行的,如果要实现不换行需要在变量末尾加上逗号 # ...

  5. stm32f4xx标准外设固件库

    STM32F4的相关资料:http://www.stmcu.org/document/list/index/category-523 一.标准固件库简介 本文下载的是STM32F4xx_DSP_Std ...

  6. Xcode开发技巧之code snippets(代码片段)

    一.什么是代码片段 当在Xcode中输入dowhile并回车后,Xcode会出现下图所示的提示代码: 这就是代码片段,目的是使程序员以最快的速度输入常用的代码片段,提高编程效率.该功能是从Xcode4 ...

  7. [LOJ2540] [PKUWC2018] 随机算法

    题目链接 LOJ:https://loj.ac/problem/2540 Solution 写的时候脑子不太清醒码了好长然后时间\(LOJ\)垫底... 反正随便状压\(dp\)一下就好了,设\(f[ ...

  8. [洛谷P1714]切蛋糕

    题目大意:给你n个整数,求出其中长度不超过m的最大字段和. 题解:单调队列维护前缀和最小值,然后用当前值减去当前有效最小值即可 C++ Code: #include<cstdio> usi ...

  9. LOJ2537:[PKUWC2018]Minimax——题解

    https://loj.ac/problem/2537 参考了本题在网上能找到的为数不多的题解. 以及我眼睛瞎没看到需要离散化,还有不开longlong见祖宗. ——————————————————— ...

  10. UVA.10192 Vacation (DP LCS)

    UVA.10192 Vacation (DP LCS) 题意分析 某人要指定旅游路线,父母分别给出了一系列城市的旅游顺序,求满足父母建议的最大的城市数量是多少. 对于父母的建议分别作为2个子串,对其做 ...