sqlsql-serversql-server-2014-express

Schedule import csv to SQL Server 2014 Express edition


Is there a way to have a .csv or .txt imported into SQL Server automatically?

I know how to do it manually using Date import & Export tool. But is it possible to do it automatically?


Solution

  • You can use Windows Task Scheduler to run bcp commands automatically. The command that will be run automatically will import your csv file using bulk copy program (bcp) utility. It can import or export data from/to files. For example to import a csv file to a table in SQL Server, you can use command like this:

    bcp.exe dbo.MyTable in "C:\Some Folder\Data.csv" -s MYPC\SQLEXPRESS -d MyDatabase -U LoginName -P StrongP@ssw0rd
    

    Where:

    Then create a new scheduled task (Start -> Task Scheduler -> Create Basic Task) and set a schedule according your requirements (e.g. daily at 3:00 AM) to run the command above.