是否需要在 MySQL 中新增 DEFAULT NULL?
否,沒有必要,因為在不新增 DEFAULT NULL 的情況下,它會給出 NULL 值。比如說,你沒有新增 DEFAULT NULL,並且插入一個沒有值的記錄,那麼結果會顯示 NULL 值作為插入的值。
我們先建立一個表 -
mysql> create table DemoTable ( FirstName varchar(100) ); Query OK, 0 rows affected (0.57 sec)
使用 insert 命令在表中插入一些記錄 -
mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.12 sec)
使用 select 語句從表中顯示所有記錄 -
mysql> select *from DemoTable;
這會產生以下輸出 -
+-----------+ | FirstName | +-----------+ | Chris | | NULL | | NULL | | David | +-----------+ 4 rows in set (0.00 sec)
廣告