INSERT INTO ... SELECT为所有MySQL列 [英] INSERT INTO...SELECT for all MySQL columns

查看:155
本文介绍了INSERT INTO ... SELECT为所有MySQL列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从以下位置移出旧数据:

I'm trying to move old data from:

this_table >> this_table_archive

复制所有列.我已经尝试过了,但是不起作用:

copying all columns over. I've tried this, but it doesn't work:

INSERT INTO this_table_archive (*) VALUES (SELECT * FROM this_table WHERE entry_date < '2011-01-01 00:00:00');

注意:这些表是相同的,并且已将id设置为主键.

Note: the tables are identical and have id set as a primary key.

推荐答案

如果id列是一个自动递增的列,并且两个表中都已经有一些数据,那么在某些情况下,您可能希望从列列表中省略该id并生成新的id,以避免插入已经存在的id在原始表格中.如果您的目标表为空,那么这将不是问题.

If the id columns is an auto-increment column and you already have some data in both tables then in some cases you may want to omit the id from the column list and generate new ids instead to avoid insert an id that already exists in the original table. If your target table is empty then this won't be an issue.

这篇关于INSERT INTO ... SELECT为所有MySQL列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆