每當我向宣告為非空值的 MySQL 列中插入空字串時,它為何顯示 0 而不是空字串?
這是因為插入空字串意味著我們插入了一些值,而不是 NULL。空字串顯然對映為 0,表示為整數。換句話說,我們認為透過插入空字串,我們為 MySQL 提供了一個整數表示為 INT 0 的值。考慮以下示例,其中我們插入了一個空字串,它被 MySQL 對映為 0。
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)
廣告
資料結構
網路
關係型資料庫
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP