登录
首页 >  数据库 >  MySQL

MySQL 查询使日期列为 NULL?

来源:tutorialspoint

时间:2023-08-26 21:21:56 225浏览 收藏

目前golang学习网上已经有很多关于数据库的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《MySQL 查询使日期列为 NULL?》,也希望能帮助到大家,如果阅读完后真的对你学习数据库有帮助,欢迎动动手指,评论留言并分享~

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 −

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?》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:tutorialspoint 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>