NULL and Empty String in Mysql

NULL and Empty String in Mysql

I recently came into contact with MySQL. Yesterday I created a new table to store table structure information:

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';

Then query the tablist table:

See which columns have no comments:

select * from tablist where COLUMN_COMMENT is null;

The result I found was Empty set. However, from the above query results and Navicat, we can see that the null value is displayed as the word 'null' in the result set, while the empty string is displayed as empty.

After checking the information, I found that there is a difference between the null value and the empty string in Mysql. It is very strange that after the COLUMN_COMMENT is inserted, the null value turns into an empty string (the reason is unknown).

Use select * from tablist where COLUMN_COMMENT=''; and the query works fine.

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.

In MySQL's myisam engine, null values ​​take up additional storage space (1 bit), while empty strings take up no space at all. At the same time, null values ​​cannot be stored in B-tree indexes, which will cause serious performance problems when the amount of data is large.

The query methods of the two are also different: null value query uses is null/is not null query, while empty string can be queried using = or !=.

Summarize

The above is what I introduced to you about NULL and Empty String in Mysql. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • The MySQL server is running with the --read-only option so it cannot execute this statement
  • mysql databasemysql: [ERROR] unknown option ''--skip-grant-tables''
  • Detailed explanation of ensuring the consistency of MySQL views (with check option)
  • Solution to the error message "java.sql.SQLException: Incorrect string value:'\xF0\x9F\x92\xA9\x0D\x0A...'" when storing emoticons in MySQL
  • An example of connecting mysql with php via odbc to any database
  • Detailed explanation of installing and completely uninstalling mysql with apt-get under Ubuntu
  • Examples of the correct way to use AES_ENCRYPT() and AES_DECRYPT() to encrypt and decrypt MySQL
  • mysql server is running with the --skip-grant-tables option
  • Detailed explanation of using pt-heartbeat to monitor MySQL replication delay
  • Introduction to the use of MySQL pt-slave-restart tool

<<:  Top 10 Js Image Processing Libraries

>>:  How to transfer files between Windows and Linux

Recommend

Solution for FileZilla 425 Unable to connect to FTP (Alibaba Cloud Server)

Alibaba Cloud Server cannot connect to FTP FileZi...

Summary of frequently used commands for Linux file operations

0. New operation: mkdir abc #Create a new folder ...

Let's talk about the v-on parameter problem in Vue

Use of v-on:clock in Vue I'm currently learni...

MySQL table name case selection

Table of contents 1. Parameters that determine ca...

JS implements array filtering from simple to multi-condition filtering

Table of contents Single condition single data fi...

Detailed process of configuring Https certificate under Nginx

1. The difference between Http and Https HTTP: It...

Vue custom directive details

Table of contents 1. Background 2. Local custom i...

Implementation of CSS border length control function

In the past, when I needed the border length to b...

MySQL 8.0.21 installation tutorial under Windows system (illustration and text)

Installation suggestion : Try not to use .exe for...

CSS tips for implementing Chrome tab bar

This time let’s look at a navigation bar layout w...

How to fix the four sides of the table to scroll up, down, left and right

question: When I was doing project statistics rec...

Summary of common problems and application skills in MySQL

Preface In the daily development or maintenance o...

JS Canvas interface and animation effects

Table of contents Overview Canvas API: Drawing Gr...

React sample code to implement login form

As a Vue user, it's time to expand React. Fro...