Get the App
SLTechnology News&Howtos  ›  Database  › 

How mysql deletes empty data

Shulou Source: shulou.com Published: 2022-05-31 11:08:50 11月14日 Update

This article mainly introduces the relevant knowledge of mysql how to delete empty data, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this mysql article on how to delete empty data. Let's take a look.

In mysql, you can use the delete statement with "NULL" to delete empty data, which is used to delete the data record in the table, "NULL" is used to indicate that the data is empty, and the syntax is "delete from table name where field name =''OR field name IS NULL;".

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How does mysql delete empty data

Use the delete command to delete blank lines in MySQL.

The syntax is as follows

Delete from yourTableName where yourColumnName=''OR yourColumnName IS NULL

The above syntax removes blank lines and NULL lines.

To understand this concept, let's create a table. The query to create the table is as follows

Mysql > create table deleteRowDemo-> (- > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,-> StudentName varchar (20)->)

Insert some records in the table using the insert command.

The query is as follows

Mysql > insert into deleteRowDemo (StudentName) values ('John'); mysql > insert into deleteRowDemo (StudentName) values (''); mysql > insert into deleteRowDemo (StudentName) values (''); mysql > insert into deleteRowDemo (StudentName) values (NULL); mysql > insert into deleteRowDemo (StudentName) values ('Carol'); mysql > insert into deleteRowDemo (StudentName) values (' Bob'); mysql > insert into deleteRowDemo (StudentName) values (''); mysql > insert into deleteRowDemo (StudentName) values ('values)

Use the select statement to display all records in the table.

The query is as follows

Mysql > select * from deleteRowDemo

Here is the output

+-+-- +-+ | Id | StudentName | +-+-+ | 1 | John | 2 | | 3 | | 4 | NULL | | 5 | Carol | | 6 | Bob | | 7 | | 8 | David | + -+ 8 rows in set (0.00 sec)

This is a query that deletes blank lines and NULL

Mysql > delete from deleteRowDemo where StudentName='' OR StudentName IS NULL

Now, let's check the table record again.

The query is as follows

Mysql > select * from deleteRowDemo

Here is the output

+-this is the end of the article on "how to delete empty data by mysql". This is the end of the article on "how to delete empty data by mysql". This is the end of the article. Thank you for reading! I believe you all have a certain understanding of "how to delete empty data in mysql". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Data query knowledge blank lines statements grammar content commands fields articles output value again easy to operate tutorials articles easy to understand more concepts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi Apple vpn Huawei