Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I want to import thousands of record from a csv file and same time I also need to manage parent child relationship for Inserting Data in tables.

I have used SQLBulkCopy to Import data, and in terms of performance its fast.
But I am not able to manage parent child Relationship for Inserting Data in two different tables.

Can Any one guide me that how can its possible ?
or is there any other way to do this except SQLBulkCopy ?

MY Requirement IS : I want to Import thousands of records using Parent Child relationship (performance is key point).

Please provide suggestions.

Thanks,
Rajan Bajania
Posted
Comments
Prasad Avunoori 24-Jun-14 4:59am    
Are parent and child records exist in same csv file? Can you please share the field details of it?
RBajania 24-Jun-14 9:21am    
Hi Prasad,
Thanks for your response.

Yes Both Parent and Child records are in same csv file.

CompanyName,Address,City,Contact1,JobTitle1,Contact2,JobTitle2,Contact3,JobTitle3,Contact4,JobTitle4

The Above is The Header Of My csv
In My Case I have Parent Table of Company and Child table of Contact. so One Company and multiple Contacts.
Currently I have created a cursor and passed a Table to it from front end (Using User Defined Table Type).
but its too slow and time out occurs as there are around 50000 records in csv and in future I can have more records too.

One quick suggestion is to import all the records in a temporary table using SQLBulkCopy. Once all records gets imported then you execute a stored procedure who first import parent records and then import child records from temp table with updated reference keys with respect to the parent tables
 
Share this answer
 
Then you have to try some thing Like SSIS(SQL Server Integration services) Google it you have lot info you will get for your solution
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900