最近新接觸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使用=或者!=查詢即可。
總結
以上所述是小編給大家介紹的Mysql中的NULL和Empty String,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
您可能感興趣的文章:- The MySQL server is running with the --read-only option so it cannot execute this statement
- mysql數據庫mysql: [ERROR] unknown option ''--skip-grant-tables''
- mysql視圖之確保視圖的一致性(with check option)操作詳解
- MySQL存儲表情時報錯:java.sql.SQLException: Incorrect string value:‘\xF0\x9F\x92\xA9\x0D\x0A...’的解決方法
- javascript連接mysql與php通過odbc連接任意數據庫的實例
- ubuntu下apt-get安裝和徹底卸載mysql詳解
- MySQL利用AES_ENCRYPT()與AES_DECRYPT()加解密的正確方法示例
- mysql server is running with the --skip-grant-tables option
- 利用pt-heartbeat監控MySQL的復制延遲詳解
- MySQL pt-slave-restart工具的使用簡介