SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


insert data from file to sql table


insert data from file to sql table

Author
Message
harri.reddy
harri.reddy
Old Hand
Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)

Group: General Forum Members
Points: 395 Visits: 346
hi
i have flat file like this

TH*4.2*876545*P~~IO*3456*color~

now i have two tables

create table table1
(id nvarchar(10),
t1 int,
t2 int primary key,
t3 nvarchar(5),
i1 int foreign key table2(i1))

create table table2(
id nvarchar(10),
i1 int primary key,
i2 nvarchar(10))

now i need to insert this file record into table describe below.

i cannot do it mannualy.

if i use ssis package ,how can i1 value of table 1 will automatically insetered.

any other way

thanks
GSquared
GSquared
SSC Guru
SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)

Group: General Forum Members
Points: 58387 Visits: 9730
Insert it into a staging table first.

Is there anything in the file that identifies the rows uniquely? Like a row number or anything like that?

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
harri.reddy
harri.reddy
Old Hand
Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)

Group: General Forum Members
Points: 395 Visits: 346
no in the file there is no row number

i need to know how to insert data into table which has primary -?foreign key relation.

as you said staging table

can you give me example.like i have given you two tables,can you explain me with that example
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63202 Visits: 13298
harri.reddy (10/24/2012)
no in the file there is no row number

i need to know how to insert data into table which has primary -?foreign key relation.

as you said staging table

can you give me example.like i have given you two tables,can you explain me with that example


Can you give a bit more sample data and the desired output? It's not really clear what you want to do with the flat file rows.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
harri.reddy
harri.reddy
Old Hand
Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)

Group: General Forum Members
Points: 395 Visits: 346
TH*4.2*876545*P~~IO*3456*color~ n

my data would be like this

table1
id t1 t1 t3 i1
TH 4.2 876545 p 3456

table2

id i1 i2
iO 3456 color

i need to do it using ssis

here,i1 is primary key of table2 , which is foreign key of table1

thanks
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63202 Visits: 13298
Use * as the delimiter for your flat file in the flat file connection manager.
Duplicate the stream using the Multicast.

Put two OLE DB destinations to your table, but write only the columns needed for the corresponding table.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
harri.reddy
harri.reddy
Old Hand
Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)

Group: General Forum Members
Points: 395 Visits: 346
but how can i write primary -?foreign key in first table(i1)
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63202 Visits: 13298
You just write the same column (number 5 in your flat file) twice to the database.
Once as a PK, once as a FK. So you need two OLE DB Destinations in your dataflow.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
harri.reddy
harri.reddy
Old Hand
Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)Old Hand (395 reputation)

Group: General Forum Members
Points: 395 Visits: 346
u mean in header row delimiter i need to put *
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search