
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 −
云EC电商系统(简称云EC)是由佛山市云迈电子商务有限公司自主开发的一套免费、开源的基于PHP+MYSQL电商系统软件。 云EC电商系统 1.2.1 更新日志:2018-08-10 1.修复部分环境下二维码不显示的问题; 2.商品列表增加多属性筛选支持; 3.修复更新优惠券状态时错将已使用的优惠券也更新为过期; 4.修复文章发布远程图片下载失败; 5.修复某些情况下运费计算出错导致
2595
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?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号