October 7, 2010 at 8:26 am
Greetings again helpers.
I have a .csv file with 5 columns:
postID varchar(3)
datePosted varchar(7)
BookNumber int
Title varchar(100)
Amount Money
I want to import this .csv file into sql server.
I know how to do this by using BULK Insert
BULK INSERT Catalogues
FROM 'c:\filename.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = ''
)
The problem that I have that this import is done regularly and data on csv file is usually different.
The way we want to go about is to check the db to see if the data we are about to import already exists.
If yes, update it. If no, insert it.
I don't believe BULK insert can do this.
Any help is greatly appreciated.
October 7, 2010 at 8:28 am
You could use Bulk Insert to upload the data into a temporary table then compare that data with what's in the permanent table.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
October 7, 2010 at 8:36 am
I personally would lean towards SSIS since I think it allows you more choices about what to do, and better control over security, but bulk insert will work fine.
I like Alvin's advice, though I would make a permanent staging table. Import the data there, then look at MERGE as a way to send this to your permanent table.
October 7, 2010 at 8:43 am
I like Steve's advice. I prefer using SSIS but I know this not everybody feels the same way. That's why I did not recommend it.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
October 7, 2010 at 9:06 am
Your right Alvin, I would have liked SSIS but have not used it before.
Do you guys have any easy to follow example?
Thanks alot guys.
October 7, 2010 at 9:27 am
Without using SSIS read this for an explanation and sample code.
http://technet.microsoft.com/en-us/library/bb522522.aspx
If you want to use the MERGE statement in an SSIS package refer to:
October 7, 2010 at 1:24 pm
Thanks a lot guys.
October 7, 2010 at 4:39 pm
I may be in a minority here. To me, SSIS is a four letter word. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
October 7, 2010 at 7:00 pm
Jeff Moden (10/7/2010)
I may be in a minority here. To me, SSIS is a four letter word. 😉
There's nothing wrong with SSIS, but there are wrong ways to use SSIS. 🙂
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
October 10, 2010 at 10:14 pm
Alvin Ramard (10/7/2010)
Jeff Moden (10/7/2010)
I may be in a minority here. To me, SSIS is a four letter word. 😉There's nothing wrong with SSIS, but there are wrong ways to use SSIS. 🙂
I've admitted not done performance tests on my own but my understanding is that even the Bulk Insert task is slower than just using Bulk Insert. And what's the big deal? SSIS doesn't really give you anything better for importing CSV's... it just allows you to do some of the coding by clicking and dragging.
Last but not least, I avoid using a permanent staging table like the plague because I might want to have more than one instance of the code running on different files for purposes of parallel loading. Most of the ETL systems I've designed have had to handle hundreds of files per day with multiple instances of the "importer" running. A permanent staging table would be a whole lot more difficult to manage for concurrance especially when it comes to the wholesale table locking during validation updates to the data in the table.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 11, 2010 at 8:08 am
Jeff Moden (10/10/2010)
Alvin Ramard (10/7/2010)
Jeff Moden (10/7/2010)
I may be in a minority here. To me, SSIS is a four letter word. 😉There's nothing wrong with SSIS, but there are wrong ways to use SSIS. 🙂
I've admitted not done performance tests on my own but my understanding is that even the Bulk Insert task is slower than just using Bulk Insert. And what's the big deal? SSIS doesn't really give you anything better for importing CSV's... it just allows you to do some of the coding by clicking and dragging.
Last but not least, I avoid using a permanent staging table like the plague because I might want to have more than one instance of the code running on different files for purposes of parallel loading. Most of the ETL systems I've designed have had to handle hundreds of files per day with multiple instances of the "importer" running. A permanent staging table would be a whole lot more difficult to manage for concurrance especially when it comes to the wholesale table locking during validation updates to the data in the table.
I like SSIS but I will agree with you that it's not necessarily the best option for a simple file upload.
Using a permanent staging table, with multiple process running at the same time, and each one starting with "TRUNCATE TABLE ...", could lead to interesting, and unexpected (by some people), results.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply