[英]How I can copy a table columns with data from one database to another database?
The story is that I want to copy a table column data in a database to another table of another database. 故事是我想将数据库中的表列数据复制到另一个数据库的另一个表中。 Both database are on same sql server 2005. Is this possible to copy the data in this manner or used to any software for do this. 两个数据库都在同一台sql server 2005上。这是否可以这种方式复制数据或用于任何软件。 I am using only one column with different table names and only copy the column data. 我仅使用一列具有不同表名的列,并且仅复制列数据。 please do the needful. 请只做那些需要的。
Note: this question may be duplicate but I did not get the solutions. 注意:这个问题可能是重复的,但我没有解决办法。 thanks 谢谢
If you want to simply copy rows from a source database to a target database, something like this should work, assuming the databases are on the same server, which you said they were: 如果您只想将行从源数据库复制到目标数据库,则假设数据库位于同一台服务器上(您说它们在同一台服务器上),则应该可以执行以下操作:
Insert Into TargetDatabase.SchemaName.TableName (TargetColumn)
Select SouorceColumn
From SourceDatabase.SchemaName.TableName
If you want to synchronize rows (eg, update or delete rows based on some criteria) between two tables in two different databases, this is far more complex. 如果要在两个不同数据库中的两个表之间同步行(例如,基于某些条件更新或删除行),则要复杂得多。 I would suggest a tool like Red-Gate Data Compare, or maybe some freeware app that does this. 我建议使用类似Red-Gate Data Compare的工具,或者一些执行此操作的免费软件。 If you are using SQL Server 2008, the MERGE statement might work for you as well. 如果使用的是SQL Server 2008,则MERGE语句也可能适用。
If you are looking to sync the data vs doing a simple insert I highly recommend using the tools from http://www.red-gate.com/ . 如果您要同步数据而不是简单插入,我强烈建议您使用http://www.red-gate.com/中的工具。 Specifically sql data compare. 具体来说sql数据比较。
-- Destitination Test2.dbo.AA not existing
Select *
Into Test2.dbo.AA
from Test.dbo.AA
-- Destitination Test2.dbo.AA existing
INSERT
Into Test2.dbo.AA
Select *
from Test.dbo.AA
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.