dbTalk Databases Forums  

Importing a flat file into a normalized database

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


Discuss Importing a flat file into a normalized database in the microsoft.public.sqlserver.dts forum.



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

Default Importing a flat file into a normalized database - 11-08-2004 , 11:24 PM






I have a database that I normalized to 3N. Now I have a large amount of data
from a 3rd party that is in a flat file that I wish to bring into the
normalized (but empty) database. If I simply needed to split the data up
into the appropriate tables, I can see to build multiple inserts using a
temp table. What I cannot figure out is how to create my 1-to-many
relationships as I do the inserts. I've read several posts on this topic,
but none that really give any specific guidance. Any advice?



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

Default Re: Importing a flat file into a normalized database - 11-09-2004 , 12:14 AM






OK so what I would do is this

Import the file into a working table of the same structure

Import the Parent attributes to the real table(s)
Import the child attributes. You will need to join back onto the working
table.

This will involve making multiple passes over the same data.

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.Konesans.com


"Earl" <brikshoe (AT) newsgroups (DOT) nospam> wrote

Quote:
I have a database that I normalized to 3N. Now I have a large amount of
data from a 3rd party that is in a flat file that I wish to bring into the
normalized (but empty) database. If I simply needed to split the data up
into the appropriate tables, I can see to build multiple inserts using a
temp table. What I cannot figure out is how to create my 1-to-many
relationships as I do the inserts. I've read several posts on this topic,
but none that really give any specific guidance. Any advice?




Reply With Quote
  #3  
Old   
Earl
 
Posts: n/a

Default Re: Importing a flat file into a normalized database - 11-09-2004 , 08:16 AM



Thanks Allan, I will work with that.

"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
OK so what I would do is this

Import the file into a working table of the same structure

Import the Parent attributes to the real table(s)
Import the child attributes. You will need to join back onto the working
table.

This will involve making multiple passes over the same data.

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.Konesans.com


"Earl" <brikshoe (AT) newsgroups (DOT) nospam> wrote in message
news:%23wmZjxhxEHA.260 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
I have a database that I normalized to 3N. Now I have a large amount of
data from a 3rd party that is in a flat file that I wish to bring into the
normalized (but empty) database. If I simply needed to split the data up
into the appropriate tables, I can see to build multiple inserts using a
temp table. What I cannot figure out is how to create my 1-to-many
relationships as I do the inserts. I've read several posts on this topic,
but none that really give any specific guidance. Any advice?






Reply With Quote
  #4  
Old   
Earl
 
Posts: n/a

Default Re: Importing a flat file into a normalized database - 12-31-2004 , 02:40 PM



Thanks Allan. It sounds like you are saying to import to the Parent table,
creating an Identity primary key, then doing the Inserts back into the child
tables, using the PK as the FK for the child tables?

"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
OK so what I would do is this

Import the file into a working table of the same structure

Import the Parent attributes to the real table(s)
Import the child attributes. You will need to join back onto the working
table.

This will involve making multiple passes over the same data.

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.Konesans.com


"Earl" <brikshoe (AT) newsgroups (DOT) nospam> wrote in message
news:%23wmZjxhxEHA.260 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
I have a database that I normalized to 3N. Now I have a large amount of
data from a 3rd party that is in a flat file that I wish to bring into the
normalized (but empty) database. If I simply needed to split the data up
into the appropriate tables, I can see to build multiple inserts using a
temp table. What I cannot figure out is how to create my 1-to-many
relationships as I do the inserts. I've read several posts on this topic,
but none that really give any specific guidance. Any advice?






Reply With Quote
  #5  
Old   
Michael Cheng [MSFT]
 
Posts: n/a

Default Re: Importing a flat file into a normalized database - 01-05-2005 , 06:33 AM



Hi Earl,

suppose the flat table is following:

pk1 pa1 ck1 ca1
pk1 pa1 ck2 ca1
pk2 pa2 ck3 ca1
pk2 pa2 ck4 ca1

pk= parent table primary key
pa= parent table attribute
ck= child table primary key
ca=child table attribute

we may use the following method:

1. create temp table by select pk, pa columns

2. Select distinct to get the primary table

3. Select ck, ca, pk column into the child table directly. pk is foregin
key in the child table at this time.

Hope it helps.

Sincerely yours,

Michael Cheng

Online Partner Support Specialist
Partner Support Group
Microsoft Global Technical Support Center
---------------------------------------------------------------
Get Secure! - http://www.microsoft.com/security

This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only, many thanks!


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.