如何用TRIGGERS在MySQL表中插入DATE?

让我们首先创建一个表-

create table DemoTable1584
   -> (
   -> DueDate datetime
   -> );

这是在MySQL中插入DATE的查询-

create trigger insertDate before insert on DemoTable1584
   ->  for each row set new.DueDate=curdate();

使用插入命令在表中插入一些记录-

insert into DemoTable1584 values();
insert into DemoTable1584 values();
insert into DemoTable1584 values();

使用select语句显示表中的所有记录-

select * from DemoTable1584;

这将产生以下输出-

+---------------------+
| DueDate             |
+---------------------+
| 2019-10-18 00:00:00 |
| 2019-10-18 00:00:00 |
| 2019-10-18 00:00:00 |
+---------------------+
3 rows in set (0.00 sec)