将表复制到另一个具有不同结构的表 [英] Copy a table to another table with different structure

查看:156
本文介绍了将表复制到另一个具有不同结构的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DB中有2个表:

  Table1 
Table1_Temp

Table1_Temp是从CSV生成的。它几乎与Table1相同但不同,因为所有Table1_Temp字段都是VARCHAR,它有一些不相关的字段。



我需要将数据从Table1_Temp移动到Table1, Table1的结构,并忽略Table1_Temp中不必要的字段。



我该怎么做?

解决方案

使用并将其转换为您选择的必需类型

 插入到table1(col1,col2,col3)
中选择cast(col1 as signed),col5,col7
from Table1_Temp


I have 2 tables in the DB:

Table1
Table1_Temp

The Table1_Temp was generated from a CSV. it is almost identical to Table1 but different because all Table1_Temp fields are VARCHAR and it has some irrelevant fields.

I need to move the Data from Table1_Temp to Table1 but to keep the structure of Table1, and disregard the unnecessary fields from Table1_Temp.

How can I do it?

解决方案

Choose the columns to use and cast them to the necessary type in your select

insert into table1 (col1, col2, col3)
select cast(col1 as signed), col5, col7
from Table1_Temp

这篇关于将表复制到另一个具有不同结构的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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