Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points of null in MySQL database

2025-05-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces what are the knowledge points of null in MySQL database. What is introduced in this article is very detailed and has a certain reference value. Interested friends must finish reading it!

Null is a common occurrence in mysql databases. What are the considerations for null in mysql?

1. Is null

First of all, determine whether the value of a column in the database is null, can not be equal to determine, you must use is. For example, select * from users where user_name is null or select * from users where user_name is not null, not select * from users where user_name = null

2. ISNULL ()

The ISNULL () function is built into the MySQL database and is used in the same way as other built-in functions such as sum () provided in MySQL. For example, select ISNULL (user_name) from users where user_name = 'Demrystv' returns a value of 0 to select ISNULL (NULL) returns a value of 1

3. IFNULL ()

The IFNULL () function is built into the MySQL database and is used in the same way as other built-in functions such as sum () provided in MySQL. It mainly receives two parameters, the first parameter is the field or value to determine the null value, and the second field is the return value to be replaced if the first parameter is null, that is, if the first field is null, it will be replaced with another value. For example, select IFNULL (NULL, "java is the best language of the world"), because of the value of the first parameter NULL, will output the value of the second parameter, java is the best language of the world; similarly, if the first field is not empty, it will return the value of the first field.

4. Insert into and null

When using insert into to fill data into the table, you need to first make it clear whether the table is null or empty. If it is null, then you cannot use insert into for filling data, you must use update, which seems simple, but it is often easy to ignore in actual development, so it requires special attention.

Example:

Create a test table, colA can not store null values, colB can store null values.

CREATE TABLE `test` (`colA` varchar (255) NOT NULL, `colB` varchar (255) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8; is all the contents of this article "what are the knowledge points of null in MySQL database". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report