如何在 MySQL 中储存像“0000-00-00”这样的日期


为了在一个 MySQL 表的列中储存“0000-00-00”这样的日期,我们必须将 SQL 模式设为“allow_invalid_date”。下面的例子将演示此过程 -

mysql> SET sql_mode = 'allow_invalid_dates';
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> Create table test_date(date_order date);
Query OK, 0 rows affected (0.45 sec)

mysql> Insert into test_date(date_order) values('0000-00-00');
Query OK, 1 row affected (0.04 sec)

mysql> Select * from test_date;
+------------+
| date_order |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)

更新于: 2020 年 1 月 28 日

1 千次观看

开启你的 职业

通过完成本课程获得认证

开始吧
广告
© . All rights reserved.