最近新接觸Mysql,昨天新建一個(gè)表用于存儲(chǔ)表結(jié)構(gòu)信息:
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表:
![](/d/20211018/5b85c3fae871f333d95ef353cf1cc7b6.gif)
看看有哪些列沒有comment于是:
select * from tablist where COLUMN_COMMENT is null;
查到的結(jié)果居然是Empty set。不過從以上查詢結(jié)果和navicat都能看出:null值在結(jié)果集中顯示的是'null'的單詞,而空字符串則顯示為空。
查過資料后發(fā)現(xiàn)Mysql的null值和空字符串是有區(qū)別的,這里很奇怪COLUMN_COMMENT在經(jīng)過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值占用額外的存儲(chǔ)空間(1bit),空字符串則完全不占用空間。同時(shí)null值在B樹索引中也無法被存儲(chǔ),數(shù)據(jù)量大時(shí)會(huì)造成較嚴(yán)重的性能問題。
兩者的查詢方式也不一樣:null值查詢使用is null/is not null查詢,而empty string使用=或者!=查詢即可。
總結(jié)
以上所述是小編給大家介紹的Mysql中的NULL和Empty String,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
您可能感興趣的文章:- The MySQL server is running with the --read-only option so it cannot execute this statement
- mysql數(shù)據(jù)庫mysql: [ERROR] unknown option ''--skip-grant-tables''
- mysql視圖之確保視圖的一致性(with check option)操作詳解
- MySQL存儲(chǔ)表情時(shí)報(bào)錯(cuò):java.sql.SQLException: Incorrect string value:‘\xF0\x9F\x92\xA9\x0D\x0A...’的解決方法
- javascript連接mysql與php通過odbc連接任意數(shù)據(jù)庫的實(shí)例
- ubuntu下apt-get安裝和徹底卸載mysql詳解
- MySQL利用AES_ENCRYPT()與AES_DECRYPT()加解密的正確方法示例
- mysql server is running with the --skip-grant-tables option
- 利用pt-heartbeat監(jiān)控MySQL的復(fù)制延遲詳解
- MySQL pt-slave-restart工具的使用簡介