gpt4 book ai didi

mysql - 我们可以在使用 sequelize js Node 在 mysql 表中插入数据后给时间吗

转载 作者:行者123 更新时间:2023-12-03 22:43:55 24 4
gpt4 key购买 nike

我在 MySQL 中创建了一个订单表,其中包含 start timeclose time 等字段,使用这些字段我需要在将数据插入订单表后给时间在订单表中插入数据。

有没有可能做。

如果是,请帮助我如何解决它。

最佳答案

恕我直言,您的问题让我们猜测您想做什么。

您可以通过执行以下操作将当前时间插入一行:

  INSERT INTO orders (start_time, col1, col2) 
VALUES (NOW(), 'something', 'another thing');

您可以像这样更新一行来设置当前时间
  UPDATE orders SET close_time=NOW(), col2='some value'
WHERE col1='something';

通过像这样声明 start_time 行,您可以在插入时自动设置当前时间:
start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

但是你可能需要根据你的业务逻辑自己设置 close_time 。

如果您的 start_timeclose_time 列是用 TIMESTAMP 数据类型定义的,那么您在处理多个时区时会获得一些优势。

(start_time, col1, col2) VALUES (NOW(), 'something', 'another thing');

关于mysql - 我们可以在使用 sequelize js Node 在 mysql 表中插入数据后给时间吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55238608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com