将数据从一个表复制到另一个表。数据库不同,表结构不同 [英] Copying data from one table to another table. Databases are different and table structure is different

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

问题描述

我正在寻找我的MySQL数据复制相关问题的解决方案。
我在数据库DB1中有一个表TAB1,它包含一些数据。现在我想要将这些数据行中的一些迁移到另一个表TAB2到另一个数据库DB2。



这将是一个理想的方式为MySQL写这样的SQL脚本服务器。我不能写java / php程序等,因为我没有访问的代码库。



任何示例链接将是有帮助的。我知道这可以通过DBLink在Oracle中完成,但是如何在MySQL中完成。



感谢

 插入db2.table2(field1,field2,..,fieldN)
从db1.table1中选择field1,field2,..,fieldN

编辑。如果您需要在两个不同的数据库之间进行更新是正确的语法:

 更新
db2.table2为t2,
db1.table1为t1
set
t2.field1 = t1.field1,
t2.field2 = t1.field2,
t2.field3 = t1.field3
其中t1.id = t2。 id


I am looking for a solutions for my MySQL data copying related problem. I have a table TAB1 in a database DB1 that contains some data. Now I want some of these data rows to be migrated to another table TAB2 to some another database DB2.

What would be an ideal way to write such a SQL script for MySQL server. I cannot write java/php program etc because I don't have access to the code base.

Any example links will be helpful. I know this can be done in Oracle via DBLink but how to do it in MySQL.

Thanks

解决方案

insert into db2.table2 (field1,field2,..,fieldN)
select field1,field2,..,fieldN from db1.table1

EDIT. If you need to do an update between two different databases this is the right syntax:

update 
db2.table2 as t2,
db1.table1 as t1
set 
t2.field1 = t1.field1,
t2.field2 = t1.field2,
t2.field3 = t1.field3
where t1.id = t2.id

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

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