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

这是因为插入空字符串意味着我们要插入一些值而不是NULL。空字符串显然以整数形式映射到零。换句话说,我们可以说,通过插入空字符串,我们为MySQL提供了一个整数,该值的整数表示为INT0。请请看以下示例,在该示例中,我们插入了一个空字符串并将其映射为0。

mysql> create table test(id int NOT NULL, Name Varchar(10));

mysql> Insert into test(id, name) values('1', 'Gaurav'),('0','Rahul'),('','Aarav');
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)
猜你喜欢