针对所有列值,在 Datetime 字段中设置当前日期的 MySQL 查询
我们首先创建一个表 -
mysql> create table DemoTable821(AdmissionDate datetime); Query OK, 0 rows affected (1.24 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable821 values('2019-01-21'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable821 values('2018-11-02'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable821 values('2016-12-31'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable821 values('2015-03-19'); Query OK, 1 row affected (0.17 sec)
使用 select 语句显示表中的所有记录 -
mysql> select *from DemoTable821;
将会产生以下输出 -
+---------------------+ | AdmissionDate | +---------------------+ | 2019-01-21 00:00:00 | | 2018-11-02 00:00:00 | | 2016-12-31 00:00:00 | | 2015-03-19 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
这是在 DateTime 字段中设置当前日期的查询 -
mysql> update DemoTable821 set AdmissionDate=CURDATE(); Query OK, 4 rows affected (0.74 sec) Rows matched: 4 Changed: 4 Warnings: 0
让我们再次检查表记录 -
mysql> select *from DemoTable821;
将会产生以下输出 -
+---------------------+ | AdmissionDate | +---------------------+ | 2019-08-03 00:00:00 | | 2019-08-03 00:00:00 | | 2019-08-03 00:00:00 | | 2019-08-03 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
廣告