1

sometimes I need to move data from one database table to another table in different database. These tables are identic. So I am trying to make program in C# Winforms, but I cant figure it out. I think that I should use this:

INSERT INTO table2
    SELECT *
    FROM table1
    WHERE condition;

But how can I execute this sql command when I need two connections? Or what is the right approach?

EDIT: They aren't on same server. Any other option than throught Linked servers?

1
  • If you need to do this more than a trivial amount: purchase a tool designed to synchronise data between databases. They may appear to cost a lot, but that will be cheaper than your time. Commented Oct 11, 2018 at 10:08

2 Answers 2

3

If two databases have the same server, then you can do :

INSERT INTO [dbname].[schema].table2 (<column list >)
     SELECT * 
     FROM [dbname].[schema].table1
     WHERE condition;
Sign up to request clarification or add additional context in comments.

3 Comments

Or, if on another server: linked servers.
They aren't on same server. I forget to mention. Is linked servers the only one possibility?
@Kali26. . . Yes linked servers could be possible solution for this.
0

In addition to Yogesh's answer, if the databases are on separate servers, you will need to set up a linked server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.