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)表 ...
随机推荐
- RPC架构-美团,京东面试题目
RPC(Remote Procedure Call) RPC服务 从三个角度来介绍RPC服务:分别是RPC架构,同步异步调用以及流行的RPC框架. RPC架构 先说说RPC服务的基本架构吧.允许我可耻 ...
- [STL] map,multimap,unordered_map基本用法
map的特性是,所有元素都会根据元素的键值自动被排序.map的所有元素都是pair,同时拥有键值(key)和实值(value).pair的第一元素被视为键值,第二元素被视为实值.map不允许两个元素拥 ...
- 【bzoj4721】[Noip2016]蚯蚓 乱搞
题目描述 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」=[3.9」=3.蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓.蛐 ...
- 计蒜客 17417 Highest Tower(思维+图论)
题解: 实际上一个可行解即选取长和宽的一个,使得最后每一组选第一维的数值都不同 在此基础上,使得另一维的和最大. 然后建立图论模型 对于每一个方块,在a和b之间连边. 对于选择的方案,如果选择a-&g ...
- Selector 模型
1.服务器端: import selectors import socket sel = selectors.DefaultSelector() #生成一个select对象 def accept(so ...
- Elasticsearch cat Apis
1._cat列入所有有效命令 GET /_cat 返回:有个猫...所以不难想象为啥是cat api =^.^= /_cat/allocation /_cat/shards /_cat/shards/ ...
- BZOJ1030:[JSOI2007]文本生成器——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1030 Description JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件 ...
- CC TSUBSTR:Substrings on a Tree——题解
https://www.codechef.com/problems/TSUBSTR https://vjudge.net/problem/CodeChef-TSUBSTR 给一棵点权为字母的树,你只能 ...
- [Leetcode] valid palindrome 验证回文
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- BZOJ4896 [Thu Summer Camp2016]补退选 【trie树】
题目链接 BZOJ4896 题解 \(thu\)怎么那么喜欢出\(trie\)树的题... 我们当然可以按题意模拟建\(trie\) 询问的时候,由于存在删除操作,不满足单调性,不能直接二分答案 我们 ...