如何将数据从一个表插入另一个具有不同列数的表 [英] How to insert data from one table to another with different number of columns
问题描述
我有一张表说Table1&第二个表说Table2。
表1包含10列,而表2包含15列。 (表中有10列相同,其余五列在表2中是额外的。)
我想将数据从Table1传输到Table2并为其插入空值表2中的额外列。
我该怎么办? table1中有近500行。那么有什么快捷方式吗?
我尝试了什么:
我尝试过手动数据传输。但由于它几乎是500行,我不能手动完成。有没有脚本可以做?
I have one table say Table1 & second table say Table2.
Table1 contains 10 columns while Table2 contains 15 columns. (10 columns are same in both the table and rest five columns are extra in Table2).
I want to transfer data from Table1 to Table2 and insert null values for the extra columns in Table2.
How can i do it ? I have almost 500 rows in table1. So is there any shortcut way ?
What I have tried:
I tried manual data transfer. But since it's almost 500 rows, i can not do it manually. Is there any script to do it ?
推荐答案
试试这个
try this
INSERT INTO Table2 (col1,col2,col3.....col15) select col,col2,..col10,null,null,null,null,null from Table1
这篇关于如何将数据从一个表插入另一个具有不同列数的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!