Mysql的NULL和Empty String

最近新接触Mysql,昨天新建一个表用于存储表结构信息:

create table tablist(TABLE_SCHEMA varchar(40),TABLE_NAME varchar(40),COLUMN_NAME varchar(40),COLUMN_TYPE varchar(40),
IS_NULLABLE varchar(10),COLUMN_DEFAULT varchar(40),COLUMN_COMMENT varchar(1000),REMARK varchar(2000));

insert into tablist(TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,COLUMN_COMMENT)
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,COLUMN_COMMENT
from information_schema.`COLUMNS` where TABLE_SCHEMA=‘leo‘;

然后查询tablist表:

看看有哪些列没有comment于是:

select * from tablist where COLUMN_COMMENT is null;

查到的结果居然是Empty set。不过从以上查询结果和navicat都能看出:null值在结果集中显示的是‘null‘的单词,而空字符串则显示为空。

查过资料后发现Mysql的null值和空字符串是有区别的,这里很奇怪COLUMN_COMMENT在经过insert之后,null值居然变成了空字符串(原因未明)。

使用select * from tablist where COLUMN_COMMENT=‘‘;查询正常。

NULL columns require additional space in the row to record whether their values are NULL.For MyISAM tables, each NULL column takes one bit extra, rounded up to the nearest byte.

在Mysql的myisam引擎中,null值占用额外的存储空间(1bit),空字符串则完全不占用空间。同时null值在B树索引中也无法被存储,数据量大时会造成较严重的性能问题。

两者的查询方式也不一样:null值查询使用is null/is not null查询,而empty string使用=或者!=查询即可。

原文地址:https://www.cnblogs.com/leohahah/p/8143410.html

时间: 2024-08-29 12:21:24

Mysql的NULL和Empty String的相关文章

Difference between null and empty String

String s1 = ""; means that the empty String is assigned to s1. In this case, s1.length() is the same as "".length(), witch will yield 0 as expected. String s2 = null; means that (null) or "no value at all" is assigned to s2.

[shiro] Wildcard string cannot be null or empty. Make sure permission strings are properly formatted.

访问某页面时,出现了这个异常: java.lang.IllegalArgumentException: Wildcard string cannot be null or empty. Make sure permission strings are properly formatted. at org.apache.shiro.authz.permission.WildcardPermission.setParts(WildcardPermission.java:154) at org.apa

Check if a string is NULL or EMPTY using PowerShell

http://techibee.com/powershell/check-if-a-string-is-null-or-empty-using-powershell/1889 Check if a string is NULL or EMPTY using PowerShellby TECHIBEE on OCTOBER 10, 2012 In this post, I will show you how to verify if a string is empty, null or havin

string="" string=empty string=null

一:""与string.Empty我认为是一样的.网上有一篇被转载了几十遍的文章是这样说的string.Empty 不分配存储空间,"" 分配一个长度为空的存储空间,我认为这句话是错误并且含糊不清的. 1.实际上Empty是string类中的一个静态的只读字段,他的定义是这样的: public static readonly String Empty = ""; 也就是说string.Empty的内部实现是等于””的. 2.我要反驳string.

(转)Java 中关于String的空对象(null) ,空值(empty),空格

原文出处:Java 中关于String的空对象(null) ,空值(empty),空格 定义 空对象: String s = null; 空对象是指定义一个对象s,但是没有给该对象分配空间,即没有实例化该对象,因此,空对象在调用所有对象方法时候都会抛出异常,如s.length(), s.isEmpty()等方法. 空值: String k = ""; 空值是指一个字符床对象已经实例化,即系统已经给该变量分配了空间,只是对象的内容为空. 空格: String n = " &qu

Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty

原文:Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty public class NullToEmptyStringResolver : DefaultContractResolver { /// <summary> /// 创建属性 /// </summary> /// <param name="type">类型</param> /// <param name="

java.lang.NumberFormatException: empty String

1.错误描述 java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1020) at java.lang.Double.parseDouble(Double.java:540) service.impl.BillServiceImpl.exportBillExcel(BillServiceImpl.java:301) a

PHP中空字符串介绍0、null、empty和false之间的关系

0是数字,是empty,是false,不是null,值相当于空字符串,但类型不是字符串,去空格或强制转换为字符串型时不等于空字符串 ""的值相当于0,是empty,是空字符串,是false,不是null,不是数字字符串 null的值相当于空字符串,值相当于0,是empty,是false,不是字符串,不是数字0 "=="只要值相等就满足条件: "==="需要两个变量的值和类型都相等: strval();将变量转换为字符串类型: intval();将

tomcat 7 WARNING: A context path must either be an empty string or start with a &#39;/&#39; and do not end with a &#39;/&#39;. The path [/] does not meet these criteria and has been changed to []

tomcat 7 WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to [] 解决方法: 将server.xml中的<Context docBase="../deploy" path="/&q