计划导入 csv 到 SQL Server 2014 Express 版 [英] Schedule import csv to SQL Server 2014 Express edition

查看:30
本文介绍了计划导入 csv 到 SQL Server 2014 Express 版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 .csv.txt 自动导入 SQL Server?

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

我知道如何使用 Date import & 手动执行此操作导出工具.但是有可能自动完成吗?

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

推荐答案

您可以使用 Windows任务计划程序运行bcp 命令自动执行.将自动运行的命令将使用批量复制程序 (bcp) 实用程序导入您的 csv 文件.它可以从/到文件导入或导出数据.例如将一个 csv 文件导入到 SQL Server 中的一个表,你可以使用这样的命令:

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

地点:

  • dbo.MyTable 是架构和表名,数据应该被导入.
  • in 指明方向(将数据放入数据库,或从数据库取出数据).
  • C:\Some Folder\Data.csv" 是保存要导入的数据的文件的名称和路径.
  • MYPC\SQLEXPRESS 是计算机和 SQL Server 实例名称.
  • MyDatabase 是数据库的名称,其中 dbo.MyTable 是.
  • LoginNameStronP@ssw0rd 是用于连接到服务器的凭据(或 -E 而不是 -U-P 以使用 Windows 身份验证进行连接).
  • dbo.MyTable is the schema and table name, where data should be imported.
  • in tells the direction (put data in the database, or get data out of it).
  • "C:\Some Folder\Data.csv" is the name and path to the file holding the data to be imported.
  • MYPC\SQLEXPRESS is the computer and SQL Server instance name.
  • MyDatabase is the name of the database, where dbo.MyTable is.
  • LoginName and StronP@ssw0rd are the credentials to be used to connect to the server (or -E instead of -U and -P to connect using Windows Authentication).

然后创建一个新的计划任务(Start -> Task Scheduler -> Create Basic Task)并根据您的要求设置一个计划(例如每天凌晨 3:00)运行上面的命令.

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.

这篇关于计划导入 csv 到 SQL Server 2014 Express 版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆