Search code examples
sqlsql-serverbcp

BCP import all files from a folder to database


BCP Import

How to do BCP import with all files in a folder.

folder

  • file1.csv
  • file2.csv

Need to import both the files.

bcp <tableName> in <filename> -t "^" -r "\n" -c -C 28591 -S <databaseinstance>  -U <username> -P <password>

Using the above BCP cmd, we can import only one file at a time.


Solution

  • simple BCP command import only single file. To achieve the above we need to use looping with the command.

    I have used the following command simple command.

    for /r %i in (*) do bcp <tablename> in  %i -t "^" -r "\n" -c -C 28591 -S <databaseinstance>  -U <username> -P <password>
    

    It works.