今天測試了一下mysql的Null值

bulletming發表於2019-03-07

mysql也有這個NULL常量

mysql> insert into test values(NULL);
Query OK, 1 row affected (0.00 sec)

查詢NULL值得時候要用is null或者is not null

下邊例子還說明幾個小問題:


1.null在排序中算最小值(記得oracle裡相反)

2.change column 為not null會將原先的not null更改為0

change column 為not null的測試

mysql> select * from test order by a;
+------+
| a |
+------+
| NULL |
| 1 |
+------+
2 rows in set (0.00 sec)

mysql> alter table test change column a a int not null;
Query OK, 2 rows affected (0.06 sec)
Records: 2 Duplicates: 0 Warnings: 1

mysql> select * from test order by a;
+---+
| a |
+---+
| 0 |
| 1 |
+---+
2 rows in set (0.00 sec)

mysql> insert into test values(NULL);
ERROR 1048: Column 'a' cannot be null

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/82392/viewspace-144719/,如需轉載,請註明出處,否則將追究法律責任。

相關文章