且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL:将表复制到具有额外列的另一个表

更新时间:2023-11-27 22:30:22

您可以将时间戳添加到选择列表中,以便两个表的列列表都匹配:

You could add the timestamp to the select list so the column lists of both tables would match:

INSERT INTO tab2
SELECT *, CURRENT_TIMESTAMP()
FROM   tab1

编辑
要回答评论中的问题-您不必使用 CURRENT_TIMESTAMP().任何返回时间戳的表达式都可以.您可以使用硬编码的时间戳记:

EDIT
To answer the question in the comment - you don't have to use CURRENT_TIMESTAMP(). Any expression returning a timestamp would do. You could use a hard-coded timestamp:

INSERT INTO tab2
SELECT *, TIMESTAMP('2017-07-07 19:43:00')
FROM   tab1