dbTalk Databases Forums  

Importing CSV into multiple tables

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Importing CSV into multiple tables in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
BMoritz
 
Posts: n/a

Default Importing CSV into multiple tables - 07-19-2004 , 08:54 AM






I need to take one CSV file and import it into multiple tables in a database. What I'm not sure of how to do is specify which table the data should go into. I have successfully imported into one, but not sure how to do multiple tables. Just a point in a general direction or documentation would be helpful!
Thanks,
Brian


Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Importing CSV into multiple tables - 07-19-2004 , 09:03 AM






Number of ways to do this. Is this a Master:etail import but the details
are all in one file and you want to split it?

Personally I would

1. Import the file into a staging table as is.
2. Run over the data and import the master rows
2. Run over the data again and join the Master table to our staging table
and import the detail rows.

You can do this in one pass using lookups but you will suffer on performance

--

----------------------------

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"BMoritz" <BMoritz (AT) discussions (DOT) microsoft.com> wrote

Quote:
I need to take one CSV file and import it into multiple tables in a
database. What I'm not sure of how to do is specify which table the data
should go into. I have successfully imported into one, but not sure how to
do multiple tables. Just a point in a general direction or documentation
would be helpful!
Quote:
Thanks,
Brian




Reply With Quote
  #3  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Importing CSV into multiple tables - 07-19-2004 , 10:53 AM



So you have 2 * tables

RetailCustomer and SalesCustomer.

I won't go into how this would on the face of it seem to be a bad design but
here we go with a solution

1. Should I have each table in a seperate file?

Perhaps. Can you identify easily what is what? If ==yes then you can still
import into a staging table on the SQL Server and then use TSQL

Does the file contain the same data for both types of customer? If it does
then this serves to illustrate my point that you should only have one
Customers table with a flag for "Retail" or "Sales"

Splitting your source files into their respective destination tables would
be easy as well.



--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.konesans.com - Consultancy from the people who know


"BMoritz" <BMoritz (AT) discussions (DOT) microsoft.com> wrote

Quote:
I'm not a SQL guru, so I'll try to explain a little better. I have one CSV
file with information for example a wholesale customer and a retail
customer. Each of those (wholesale customer and a retail customer) are a
table in my DB, and within that table is name, address, phone number, etc. I
need to have that CSV file import the data of the name, address, phone into
the corresponding tables. Is it better to have each table in a separate CSV?
This process will be set and done by a user, not an automated interval.
Quote:
Thanks for your time (and sorry for the multiple posts, the site gave and
error that it did not post and to try again) O-well...

Brian

"Allan Mitchell" wrote:

Number of ways to do this. Is this a Master:etail import but the
details
are all in one file and you want to split it?

Personally I would

1. Import the file into a staging table as is.
2. Run over the data and import the master rows
2. Run over the data again and join the Master table to our staging
table
and import the detail rows.

You can do this in one pass using lookups but you will suffer on
performance

--

----------------------------

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"BMoritz" <BMoritz (AT) discussions (DOT) microsoft.com> wrote in message
news:92DA7A78-E45B-4537-8B49-0B5D4BB94252 (AT) microsoft (DOT) com...
I need to take one CSV file and import it into multiple tables in a
database. What I'm not sure of how to do is specify which table the data
should go into. I have successfully imported into one, but not sure how
to
do multiple tables. Just a point in a general direction or documentation
would be helpful!
Thanks,
Brian







Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.