Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Automatic Import of CSV to SQL database table

Author  Topic 

Crash886
Starting Member

2 Posts

Posted - 2011-06-16 : 10:17:42
Hello all,

I am very new to SQL 2008. Here is my situation :

We have someone who will be uploading us a .csv on a 2X a day basis to a directory on our SQL server. We would like to run an automatic import of these .csv files to a table in a database so that nobody has to perform the import manually. I would like to avoid using VB or any kind of scripting for this if possible.

Are there any built in utilities for SQL 2008 that would be able to schedule the import of all files (or only all new files) in a directory to a database? I feel SQL 2000 used to have this option in DTS but I do not see it in the SQL server import/export wizard. Any help would be greatly appreciated! Thank you in advance.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2011-06-16 : 14:45:22
you can create an SSIS package or just a simple BCP script and schedule a job to pickup the packages and export the data

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2011-06-17 : 01:39:07
Crash886 , the most straightforward way is to create a Bulk Insert procedure - check here for information- http://www.sqlserver-dba.com/2011/05/bulk-insert-csv-into-a-sql-server-table.html .
Then Schedule a job twice a day - to run the code.
To make it manageable - maybe you could add a Log Table to record activity .


Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

Crash886
Starting Member

2 Posts

Posted - 2011-06-20 : 14:23:25
Thanks guys. Jack - I know at one point the tutorial you linked says to drop the table. Is this neccesary to do? I ask because we need this table to grow, and the file will be different each time we import. Also, will we have to check for duplicates or will SQL server import anything and everything whether there are duplicates or not? Thanks again to everyone helping out.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2011-06-21 : 01:42:08
Crash686, The tutorial drops the staging table , to clean up the space. Of course , if you want to maintain the staging table - that is fine , it depends on the application.
Once you get the data in to the staging table, deduplicate the data , before you move it onto the main table

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -