简体   繁体   English

将行复制到另一个表并创建新的时间戳

[英]Copy a row to another table and create new timestamp

In MySQL, I would like to copy data from my users_temp table to my users_final table. 在MySQL中,我想将users_temp表中的数据复制到users_final表中。 The fields are identical. 字段相同。

Here comes my query: 我的查询来了:

INSERT users_final (username, password, email)
  SELECT username, password, email)
  FROM users_temp
  WHERE id=8

My users_final table also contains a field "stamp_created". 我的users_final表还包含一个字段“stamp_created”。

How do I achieve that when I copy my row from users_temp to users_final the field "stamp_created" of the newly created row will contain the current timestamp? 当我将来自users_temp的行复制到users_final时,如何将新创建的行的“stamp_created”字段包含当前时间戳?

(Of course I do not want to copy the "stamp_created" value from my users_temp table.) (当然我不想从users_temp表中复制“stamp_created”值。)

You can get the current date from the NOW() function . 您可以从NOW()函数获取当前日期。 Something like this: 像这样的东西:

INSERT users_final (username, password, email, stamp_created)
  SELECT username, password, email, NOW()
  FROM users_temp
  WHERE id=8

您可以将CURRENT_TIMESTAMP设置为默认值,并将users_final表中的stamp_created字段设置为不可为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM