- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why it shows 0 instead of empty string whenever I insert an empty string into a MySQL column which is declared as NOT NULL?
It is because inserting an empty string means that we are inserting some value and not NULL. The empty string apparently maps to zero as an integer. In other words, we can say that by inserting empty string we are providing a value to MySQL that has integer representation as INT 0. Consider the following example in which we inserted an empty string and it mapped to 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)
- Related Articles
- What role data type plays when I insert an empty string into a MySQL column which is declared as NOT NULL?
- How it is possible to insert a zero or an empty string into a MySQL column which is defined as NOT NULL?
- Empty string in not-null column in MySQL?
- Which one is better to insert NULL or empty string in MySQL?
- Which one is better in MySQL - NULL or empty string?
- Check if a String is not empty ("") and not null in Java
- How to update empty string to NULL in MySQL?
- Insert default into not null column if value is null in MySQL?
- How do I check if a column is empty or null in MySQL?
- How to test String is null or empty?
- Check if a String is empty ("") or null in Java
- Check if a String is whitespace, empty ("") or null in Java
- Java Program to Check if a String is Empty or Null
- Split a string and insert it as individual values into a MySQL table?
- How to remove an empty string from a list of empty strings in C#?

Advertisements