Score:0

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

in flag

Hai I need help to insert data from one sql server ip to another sql server ip. I've tried using sqlcmd but it not work like mysql syntax on bash which can insert data using csv or txt file after I manipulate data with awk.

In this case there are 2 tables and 2 IP:

  • Tabel A (field: A1,A2,A3,A4,A5) on IP 22
  • Tabel 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 taskscheduler or crontab

I hope someone can help me with my case

David avatar
cn flag
What does this have to do with Ubuntu? I do not see any reference to it except in your title. No version no details nothing.
Preman Terminal avatar
in flag
@David I'm using ubuntu version 20.04 to call and send data from sql server. What kind of detail that you need to help me?
in flag
You will likely want to learn a little bit of Python for this, as that will allow you to create a script that can read from one server and write to the other. Once written, you can call that script with crontab. There are plenty of examples of how to write Python tools that read from and write to SQL Server on Stack Overflow
ch flag
You say you've tried sqlcmd, please update your question with your unsuccessful try.
Preman Terminal avatar
in flag
@Serg I don't know how to send data from files txt/csv to a table. and after I'm searching in google there are .sql to db on other IP not from file .csv or .txt. on mysql , we just need to run insert syntax. but in sqlcmd it not work because to get data we use different syntax between sqlcmd and sql server. this is my code to get data from table: ``` sqlcmd -S IP -U sa -P password -d db -Q " select * from VW_HRIS_ATT_TO_ASCEND" -o "absensi_pagi_${d}.csv" -s"|" -h-1 -W ```
Preman Terminal avatar
in flag
@matigo oke I'll try with python, do you have any suggestion link or example code?
Score:0
in flag

I'm finally found a way to solved this.

First, get data from table that we want to moved using sqlcmd.

sqlcmd -S ipdb -U sa -P "passwordsa" -d dbname -Q "select * from tabelname" -o "direktori/file.csv" -s"," -W -w 700

and then, after we adjust the file to the structure of the target table on different servers. We send it using the BCP syntax. And keep it in crontab for the running scheduler.

bcp Tablename in ~/filename.txt -S localhost -U sa -P <your_password> -d Databasename -c -t  ','

Or we can read this Link

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.