如何使用 mysql 将当前系统日期插入数据库列

发布于 2024-12-27 17:31:51 字数 247 浏览 0 评论 0原文

我在表中有三个 *date 字段,定义为 VARCHAR(45),默认值为“00-00-0000”。创建记录时,每个字段都需要当前系统时间的默认值。

我已将其中一个字段从 VARCHAR(45) 更改为 TIMESTAMP,默认值为 CURRENT_TIMESTAMP,效果很好。我想每个表只能有一个数据类型为 TIMESTAMP 的字段。

如何处理表中的其他 2 个字段?我也想 *CURRENT_TIMESTAMP 它们。

谢谢

I have three *date fields in a table defined as VARCHAR(45) with a default value of '00-00-0000'. Each of the fields needs the default value of the current system time when a record is created.

I have changed one of the fields from VARCHAR(45) to TIMESTAMP with default of CURRENT_TIMESTAMP, which works great. I think I can only have a single field with Datatype TIMESTAMP per table.

How do I handle the other 2 fields in the tables? I would like to *CURRENT_TIMESTAMP them too.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南冥有猫 2025-01-03 17:31:51

使用 NOW()< /代码>功能:

INSERT INTO yourtable (field1, field2) VALUES ('blahblah', now());

Use the NOW() function:

INSERT INTO yourtable (field1, field2) VALUES ('blahblah', now());
紫瑟鸿黎 2025-01-03 17:31:51

您可以在 MySQL 查询中使用“NOW()”来填充时间戳列的当前时间。

You can use "NOW()" in a MySQL query to fill in the current time for a timestamp column.

花想c 2025-01-03 17:31:51

您可以将 Now() 写入字段

INSERT INTO table (right_now) 
VALUES (Now()):

You can write Now() to the fields

INSERT INTO table (right_now) 
VALUES (Now()):
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文