ITPub博客

首页 > IT职业 > IT生活 > mysql约束条件not null的使用

mysql约束条件not null的使用

IT生活 作者:hongyueshan 时间:2021-09-11 09:49:49 0 删除 编辑

说明

1、该约束条件的意思是在向表中插入数据的时候,有约定条件not null的列值不能为空,否则会报错。

2、not null的字段是不能插入mull的,只能插入空值。

实例

mysql> create table t1(id int not null, name varchar(4));
Query OK, 0 rows affected (0.01 sec)
 
mysql> insert into t1 (id, name) values (1, 'python');
Query OK, 1 row affected, 1 warning (0.00 sec)
 
mysql> insert into t1 (id, name) values (1, null);
Query OK, 1 row affected (0.00 sec)
 
mysql> insert into t1 (id, name) values (null, null);
ERROR 1048 (23000): Column 'id' cannot be null

以上就是mysql约束条件not null的使用,希望对大家有所帮助。更多mysql学习指路:MySQL

推荐操作系统:windows7系统、mysql5.8、DELL G3电脑

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3676/viewspace-2829074/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-30

  • 博文量
    93
  • 访问量
    1012