通过从不同数据库中的表中选择数据,将其插入到数据库的表中 [英] insert into table in a database by selecting data from table in different database

查看:70
本文介绍了通过从不同数据库中的表中选择数据,将其插入到数据库的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仍然在我一直在努力的迁移工具上。我现在的问题是如何将数据库中的表中的记录插入到另一个数据库中的表中?(这实际上是主要的数据迁移)。

我尝试过使用SQL INSERT INTO ... SELECT语句,但我收到错误,我知道它,因为我使用单独的连接连接到两个数据库。



注意:我有一个 SOURCE DATABASE ,这是包含表格的数据库我将选择从我们称之为 SOURCE_DB 我正在使用 CONNECT 对象连接到它 CONN1



注意:我有一个< b> DESTINATION DATABASE 这是包含我将要插入的表的数据库。我们称之为 DEST_DB ,并使用名为 CONN2 CONNECTION 对象连接到它。



注意:编程语言是C#,数据库是 Sybase SQLAnywhere



请大家帮忙,提示或教程如何解决这个问题我将非常感谢。

Still on the migration tool I have been working on. My question now is how do I insert records from a table in a database to a table in another database?.( this is actually the main data migration).
I have tried using the SQL "INSERT INTO...SELECT" statements but I am getting errors and I know its because I am connecting to both databases using separate connections.

NB:I have a SOURCE DATABASE which is the database containing tables I will be SELECTING FROM let's call it SOURCE_DB and I am connecting to it using a CONNECTION object called CONN1

NB:I have a DESTINATION DATABASE which is the database containing tables I will be inserting into. Let's call it DEST_DB and I am connecting to it using a CONNECTION object called CONN2

NB:Programming language is C# and database is Sybase SQLAnywhere

Please guys any help, tip or tutorial on how to solve this will be highly appreciated.

推荐答案

SQL不是我的专业领域,但是我的工作伙伴有类似的问题,他用以下方法解决了这个问题:



http://www.mssqltips.com/sqlservertip/1704/using-merge-in-sql-server-to-insert-update-and-delete-at-the-same -time / [ ^ ]



我不知道它是否可以帮到你直接,但也许它给你另一个点o f查看找到方法。



(如果不是你可以总是试着问那个人,他看起来对它有很多了解)
SQL is not my expertise field, but a job-mate of mine had a similar issue, he solved it using:

http://www.mssqltips.com/sqlservertip/1704/using-merge-in-sql-server-to-insert-update-and-delete-at-the-same-time/[^]

I don't know if it can help you directly, but maybe it gives you another point of view to find the way.

(If not you can always try to ask that guy, he looks to know a lot about it)


您可以使用查询,例如

select * into [Destination Server] [Databasename]。[dbo]。[Tablename1]来自[Source server]。[Databasename]。[dbo]。 [Tablename2]





记住Tablename2最初不应该出现。
You can use query like
select * into [Destination Server][Databasename].[dbo].[Tablename1] from [Source server].[Databasename].[dbo].[Tablename2]


Remember Tablename2 should not present initially.


这篇关于通过从不同数据库中的表中选择数据,将其插入到数据库的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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