简体   繁体   English

如何将带有数据的表列从一个数据库复制到另一个数据库?

[英]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.

相关问题 如何将数据从一个数据库表复制到另一数据库表? - How to copy data from one database table to another database table? 我可以将数据从一个数据库表复制到另一个已经存在的数据库表sql服务器吗? - Can i copy data from one database table to another already existing database table sql server? PostgreSQL:如何将数据从一个数据库表复制到另一个数据库 - PostgreSQL: How to copy data from one database table to another database 我可以从另一个数据库复制一个数据库中的表吗? - Can I copy a table in one databsae from another database? 将数据从一个数据库中的表复制到另一个数据库 - Copy Data from a table in one Database to another database 如何仅将数据从一个数据库复制到同一网络中另一台服务器上的另一个数据库? - How can I copy only the data from one database to another one which is on other server in the same network? 将列及其数据从一个数据库中的表复制到另一台服务器中的另一表 - Copy columns and its data from a table in one database to another table in a different server 如何在postgresql中将数据从一个数据库复制到另一个数据库? - how to copy data from one database to another database in postgresql? 如何在不更改其中数据的情况下将表的模式从一个数据库导入到另一个数据库中的现有表? - How can i import a schema of a table from one database to an existing table in another without altering the data in it? 如何将数据从一个 PostgreSQL 数据库迁移到另一个(表/列名略有不同)? - How can I migrate data from one PostgreSQL database to another (with slightly different table/column names)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM