To make a date column null, use ALTER TABLE and MODIFY and set the date to NULL. Following is the syntax ?
alter table yourTableName modify column yourColumnName date NULL;
首先讓我們創(chuàng)建一個表格。在這里,我們將列設(shè)置為NOT NULL ?
mysql> create table DemoTable ( ShippingDate date NOT NULL ); Query OK, 0 rows affected (0.78 sec)
Now, insert NULL value in the above table. An error would generate since we have set the column to be NOT NULL ?
mysql> insert into DemoTable values(null); ERROR 1048 (23000) − Column 'ShippingDate' cannot be null
Now, let us alter the table and allow NULL in the above table ?
mysql> alter table DemoTable modify column ShippingDate date NULL; Query OK, 0 rows affected (1.81 sec) Records : 0 Duplicates : 0 Warnings : 0
現(xiàn)在,再次嘗試使用插入命令將NULL插入到上述表中。由于我們已經(jīng)修改了表以接受NULL,所以不會生成錯誤?
mysql> insert into DemoTable values(null); Query OK, 1 row affected (1.21 sec
Display all records from the table using select statement ?
mysql> select *from DemoTable;
這將產(chǎn)生以下輸出 ?
+--------------+ | ShippingDate | +--------------+ | NULL | +--------------+ 1 row in set (0.00 sec)
以上就是MySQL 查詢使日期列為 NULL?的詳細內(nèi)容,更多請關(guān)注php中文網(wǎng)其它相關(guān)文章!
每個人都需要一臺速度更快、更穩(wěn)定的 PC。隨著時間的推移,垃圾文件、舊注冊表數(shù)據(jù)和不必要的后臺進程會占用資源并降低性能。幸運的是,許多工具可以讓 Windows 保持平穩(wěn)運行。
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號