简体   繁体   English

将CSV更新导入SQL Server

[英]Import updating CSV into SQL Server

I'm looking for a simple solution (beginner to SQL) to allow the import of data from my .csv file to my SQL DB. 我正在寻找一个简单的解决方案(初学者到SQL),以允许从我的.csv文件导入数据到我的SQL DB。

I have a third party program that is updating my .csv file every 30 seconds and I want to put that updating information into my SQL DB. 我有一个第三方程序,每30秒更新一次.csv文件,我想把更新信息放到我的SQL DB中。 I tried the importing & exporting wizard but it didn't work due to the .csv file being utilized by the other third party program. 我尝试了导入和导出向导但由于其他第三方程序正在使用.csv文件而无法正常工作。

Getting the information into the SQL DB doesn't need to be in real time it could just retrieve all the information when opening a saved sql query file. 将信息输入SQL DB不需要实时,只需在打开保存的sql查询文件时检索所有信息。

Thank you! 谢谢!

OPENROWSET is the simplest one if you get that working in your env for CSV file. OPENROWSET是最简单的一个,如果你在你的环境中使用CSV文件。 i have seen lot of issues with what OS, and what version of MS office installed with 32bit or 64 bit. 我已经看到很多问题与什么操作系统,以及32位或64位安装的MS Office版本。

but bit more work and you will be all set with creating a small SSIS package to import that CSV in to table. 但是要做更多的工作,你将全部设置创建一个小的SSIS包,将CSV导入到表中。 execute that SSIS using SQL JOB at desired interval. 以所需的时间间隔使用SQL JOB执行该SSIS。 later if you needed more complex insert/update you can always modify the package. 稍后,如果您需要更复杂的插入/更新,您可以随时修改包。

This is the case of producer consumer problem where one process is writing data and another one is reading it. 这是生产者消费者问题的情况,其中一个进程正在写入数据而另一个正在读取数据。

Whatever you do you need to setup some kind of lock on this file that process can check if file is available for reading/writing. 无论你做什么,你需要在这个文件上设置某种锁,该进程可以检查文件是否可用于读/写。 If import/export wizard had issues with concurrency then probably other processes will also. 如果导入/导出向导存在并发问题,则可能还有其他进程。

Another option is to always create new file to write into and have reader process to always read from the newest one and delete it after processing. 另一个选择是始终创建要写入的新文件,并让读者进程始终从最新的文件中读取并在处理后将其删除。

One more thing you'll have to take care of is reading from same file multiple times. 您需要处理的另一件事是多次从同一个文件中读取。 You need some way to mark the records that have already been read so these are not inserted twice. 您需要某种方法来标记已经读取的记录,这样就不会插入两次。

All of the above is needed if this needs to be a fully automated and unattended process. 如果需要完全自动化且无人值守的过程,则需要以上所有内容。

If not you can just manually create a copy of CSV file and then use import/export wizard to import the data. 如果没有,您只需手动创建CSV文件的副本,然后使用导入/导出向导导入数据。

Here is another resource you can check out for importing CSV into SQL Server 这是您可以检出的另一个资源,用于将CSV导入SQL Server

http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/ http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-服务器/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM