简体   繁体   English

要将数据从sql server数据库传输到同一数据库的另一个副本

[英]To transfer data from sql server database to another copy of the same database

I Have two copies of the same sql server database (DB1 & DB2). 我有同一SQL Server数据库的两个副本(DB1和DB2)。 What is the best way to do the following : 什么是执行以下操作的最佳方法:

Update the data of some tables in DB2 To be the same as DB1 (ie: DB1 is the source And DB2 is the destination) and update the data of some other tables in DB1 to be the same as DB2 (ie: DB2 is the source And DB1 is the destination) 更新DB2中某些表的数据,使其与DB1相同(即:DB1是源,DB2是目标),并将DB1中其他表的数据更新为与DB2相同(即:DB2是源并且DB1是目的地)

How to make this using c# program? 如何使用C#程序做到这一点? hope to help me in the best soulution to do that. 希望能以最好的解决方案帮助我做到这一点。

keep in mind that there is no connection between the program and the two copies at the same time and the tables has many relations up on Identity columns 请记住,程序与两个副本同时没有连接,并且表在Identity列上有很多关系

Thanks :) 谢谢 :)

My suggestion would be to setup a linked server and then create stored procedure that make use of MERGE SQL command. 我的建议是设置一个链接服务器,然后创建使用MERGE SQL命令的存储过程。

Note this is semi pseudo code example 请注意,这是半伪代码示例

 MERGE DB2 AS target
    USING DB1 AS source
    ON <Primary Keys>
    WHEN MATCHED THEN 
        UPDATE SET Key = source.Value
    WHEN NOT MATCHED THEN   
        INSERT (<Columns>)
        VALUES (source.values)
        OUTPUT deleted.*, $action, inserted.* INTO #MyTempTable;

Then you can create a SqlConnection/SqlCommand and then call the stored procedure. 然后,您可以创建一个SqlConnection/SqlCommand ,然后调用存储过程。 This code you can ultimatelt host in a windows service or normal .Net event ie button click, OnLoad as example. 您可以将此代码最终托管在Windows服务或正常的.Net事件中,例如,单击按钮,例如OnLoad。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据从Excel工作表传输到SQL Server数据库 - Transfer data from Excel sheet into SQL Server database SQL数据库从一台服务器复制到另一台服务器 - Sql database copy from one server to another server 从一个DataBase(sql server 2008)到具有不同架构的另一个db(sql server 2008)的传输数据的最佳方式 - The Best Way For Transfer Data From One DataBase (sql server 2008) To Another db(sql server 2008) With Different Schema 将整个表从SQL Server CE数据库复制到另一个表 - Copy a whole table from a SQL Server CE database to another 数据从一个数据库传输到另一个数据库 - Data transfer from One database to another ASP.NET应用程序如何将最近添加的数据从SQL Server数据库复制到不同SQL Server上的另一个相似数据 - How ASP.NET application can copy recently added data from SQL Server database to another similar one on different SQL Server 将数据从Xml复制到SQL Server中数据库的表中,避免重复 - Copy Data From Xml To table in database in sql server avoiding duplications C#将数据从ODBC数据库传输到本地SQL数据库 - C# Transfer Data from ODBC Database to Local SQL Database 使用插件将数据从CRM数据库传输到SQL数据库 - Transfer data from CRM database to SQL Database using Plugin 使用C#dataAdapter.Fill()和dataAdapter.Update()将表的数据从一个数据库传输到另一个数据库的同一表 - Transfer data of a table from one database, to the same table of another database, using C# dataAdapter.Fill() and dataAdapter.Update()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM