Search code examples
sqlsql-servercronsqlcmd

How to Insert Data Field Table SQL Server from another SQL Server in different ip?


I need help to insert data from one IP to another IP of SQL Server. I've tried using sqlcmd but it doesn't work as mysql syntax works on bash which can insert data using csv or txt file after manipulation of data with awk.

In this case there are 2 tables and 2 IP:

  • Table A (field: A1,A2,A3,A4,A5) on IP 22
  • Table B (field: B1,B2,B3,... , Bn) on IP 23
  • I need to Insert data like this (A1 to B2)
  • I need to run it with task scheduler or crontab

I hope someone can help me with this case.


Solution

  • If you have a windows computer with Sql Server Management Studio (SSMS) installed, you can use the Import Wizard (right click on the table -> tasks -> import data) to create an SSIS package that will copy the data from one server to another and save the package.
    Import and Export Data with the SQL Server Import and Export Wizard

    If you want to edit the package, you will need SQL Server Data Tools. You might not need to edit it.

    Then you can create a SQL Agent Job to run the SSIS Package from the file system SQL Server Agent Jobs for Packages

    Then you could call sp_start_job from your bash script to run the SQL Agent Job. sp_start_job (Transact-SQL)

    Of course all of this depends on having the correct permissions, and there are many things that can complicate these steps, but this is the general outline.