
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;
首先让我们创建一个表格。在这里,我们将列设置为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 −
蓝心千询
蓝心千询是vivo推出的一个多功能AI智能助手
34 查看详情
mysql> alter table DemoTable modify column ShippingDate date NULL;Query OK, 0 rows affected (1.81 sec)Records : 0 Duplicates : 0 Warnings : 0
现在,再次尝试使用插入命令将NULL插入到上述表中。由于我们已经修改了表以接受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;
这将产生以下输出 −
+--------------+| ShippingDate |+--------------+| NULL |+--------------+1 row in set (0.00 sec)
以上就是MySQL 查询使日期列为 NULL?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/318136.html
微信扫一扫
支付宝扫一扫