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>
mysql not null default / default的更多相关文章
- Mysql 允许null 与 default值
分为下面4种情况: 1.允许null, 指定default值. 2.允许null, 不指定default,这个时候可认为default值就是null 3.不允许null,指定default值,不能指定 ...
- {MySQL完整性约束}一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业
MySQL完整性约束 阅读目录 一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业 一 ...
- mysql 约束条件 not null与default
not null与default 是否可空,null表示空,非字符串not null - 不可空null - 可空 use db4: 默认值,创建列时可以指定默认值,当插入数据时如果未主动设置,则自动 ...
- [MySQL数据库之表的约束条件:primary key、auto_increment、not null与default、unique、foreign key:表与表之间建立关联]
[MySQL数据库之表的约束条件:primary key.auto_increment.not null与default.unique.foreign key:表与表之间建立关联] 表的约束条件 约束 ...
- mysql Alter table设置default的问题,是bug么?
不用不知道,用了没用? 昨天在线上创建了一个表,其中有两个列是timestamp类型的,创建语句假设是这样的: create table timetest(id int, createtime tim ...
- Mysql ERROR 1067: Invalid default value for 字段
问题: //今天把一个数据库的sql文件导入到另一个数据库出现以下异常: Mysql ERROR 1067: Invalid default value for 字段 //原因是因为之前导出数据里面有 ...
- 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 ...
- mysql error 1067 invalid default timestamp
问题 MySQL 5.7版本,在创建数据表时,使用以下语句定义一个字段: `update_time` timestamp DEFAULT '0000-00-00 00:00:00' ON UPDATE ...
- Mysql is null 索引
看到很多网上谈优化mysql的文章,发现很多在谈到mysql的null是不走索引的,在此我觉得很有必要纠正下这类结论.mysql is null是有索引的,而且是很高效的,(版本:mysql5.5)表 ...
随机推荐
- struts如何在Action类中操作request,session
在servlet中,通过request.getparameter与setparameter来实现后端与前端jsp页面的数据交互,那么在struts中,也有几种方式来操作request,session实 ...
- 在intelllij中debug的时候使用log4j输出
一般在本地调试的时候,在控制台打印输出都会使用system.out.print,但是在线上运行的时候一般都是使用log4j进行日志输出. 那么在编写代码的时候,又不想写两份,直接写LOG是常规动作. ...
- 【转】关于增量链接(incremental linking)
增量链接(Incremental Linking)这个词语在使用Visual C++时经常会遇到(其实不只是VS系列,其它链接器也有这个特性), 就比如经常遇到的:上一个增量链接没有生成它, 正在执行 ...
- Maven pom 文件解释
1 - 什么是构建? 我们都知道,写完代码之后需要进行编译和运行,以笔者自身为例,使用 Eclipse 写完代码,需要进行编译,再生成 war 包,以便部署到 Tomcat. 在编写 Java 代码的 ...
- Kafka性能之道
Kafka高性能之道 高效使用磁盘 零拷贝 批处理和压缩 Partition ISR 高效使用磁盘 >顺序写cipan >Append Only(数据不更新,无记录级的数据删除,只会整个s ...
- stm32f407启动文件分析
; Amount of memory (in bytes) allocated for Stack; Tailor this value to your application needs; < ...
- [LOJ#2542] [PKUWC2018] 随机游走
题目描述 给定一棵 n 个结点的树,你从点 x 出发,每次等概率随机选择一条与所在点相邻的边走过去. 有 Q 次询问,每次询问给定一个集合 S,求如果从 x 出发一直随机游走,直到点集 S 中所有点都 ...
- hadoop压缩和解压
最近有一个hadoop集群上的备份需求.源文件有几百G,如果直接复制太占用磁盘空间.将文件从hadoop集群下载到本地,压缩之后再上传到hadoop则太耗时间.于是想到能否直接在HDFS文件系统上进行 ...
- DOM用TagName操作标签
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- poj 3498 最大流
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4809 Accepted: ...