CSV insertion using SQLCMD, how to do it?

525 Views Asked by At

I have been reading a lot of forums and tutorials where other users ask the same but the answer is almost the same always: use BCP.EXE (BULK INSERT) instead to import, and also export with BCP.EXE using native format.

But in some post I read that there is a (complicated) way to do it with SQLCMD, and my need now is strongly requesting me to to it through SQLCMD as the target is an Azure SQL DB. Does anyone know the steplist to follow? Or any useful resource that can share with me?

Thank you very much in advance.

I'm expecting to use only SQLCMD to insert the CSV data into an Azure SQL DB.

1

There are 1 best solutions below

2
Francesco Mantovani On

No, you can use SQLCMD to convert data:

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

Or BCP to import data:

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

Why don't you use SSMS to import the CSV?

enter image description here