Why whenever I insert an empty string into a MySQL column declared NOT NULL, it displays 0 instead of the empty string?

WBOY
Release: 2023-08-30 08:01:14
forward
954 people have browsed it

为什么每当我将空字符串插入声明为 NOT NULL 的 MySQL 列时,它显示 0 而不是空字符串?

This is because inserting an empty string means we are inserting some value instead of NULL. The empty string obviously maps to zero as an integer. In other words, we can say that by inserting the empty string, we are providing MySQL with an integer value represented as INT 0. Consider the following example where we have inserted an empty string and it is mapped as 0 by MySQL.

mysql> create table test(id int NOT NULL, Name Varchar(10)); Query OK, 0 rows affected (0.19 sec) mysql> Insert into test(id, name) values('1', 'Gaurav'),('0','Rahul'),('','Aarav'); Query OK, 3 rows affected, 1 warning (0.08 sec) Records: 3 Duplicates: 0 Warnings: 1 mysql> Select * from test; +----+--------+ | id | Name | +----+--------+ | 1 | Gaurav | | 0 | Rahul | | 0 | Aarav | +----+--------+ 3 rows in set (0.00 sec)
Copy after login

The above is the detailed content of Why whenever I insert an empty string into a MySQL column declared NOT NULL, it displays 0 instead of the empty string?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!