简体   繁体   English

将一个表中的多个列复制到具有额外列的另一个表中

[英]Copy multiple columns from a table to another table with extra columns

I want to copy records from one table to another table with extra columns. 我想将记录从一个表复制到具有额外列的另一表。
The table columns looks like this 表格列看起来像这样

Table1: A,B,C,...,X
Table2: A,B,C,...,X,Y,Z

I know that i can do it in the following way 我知道我可以通过以下方式做到

Insert into table2
  Select
  A,
  B,
  C, 
  ...
  X,
  '1',
  '1'
  from table1

But it is a very inefficient way if the table contains lots of columns. 但是,如果表中包含许多列,这是一种非常低效的方法。 I need to do the similar procedure for several tables. 我需要对几个表执行类似的过程。 Is there a better way to do it? 有更好的方法吗?
I tried the following but it doesn't work 我尝试了以下操作,但不起作用

insert into table2 select * , '1', '1'  from table1;

The thing you tried should work, just add alias. 您尝试过的东西应该可以工作,只需添加别名即可。

INSERT INTO table2
SELECT t1.*,
       '1',
       '1'
  FROM table1 t1;

Insert into table2 ( A, B, C, ... , X, Y , Z) SELECT ( A, B, C, ... , X, '1' , '1') from table1 ; 从table1插入到table2(A,B,C,...,X,Y,Z)中SELECT(A,B,C,...,X,'1','1');

In this case Y & Z are Strings (characters). 在这种情况下,Y和Z是字符串(字符)。

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

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