How to insert excel data into foreign key table

asp.net c# oledb sqlbulkcopy sql-server-2008

Question

I want to insert data from excel sheet to multiple tables i used sqlbulk to insert data in 1 table. tables are linked with foriegn keys. first data will be inserted in parent table after that data will go in child table.

My Excel Sheet Image: https://s5.postimg.org/yvmb0ekvr/Untitled.png

Relational Diagram: https://s5.postimg.org/h4aoly5h3/Products.png

My Question is how can i insert excel data into different tables from parent to child. I mean First data will go in Category Table then Sub-Category Table, then Brand Table, then Model table and at last Products_Info table.

Popular Answer

You can bulk insert your initial data into a staging table. Then use a series of statements to create your data in each lookup table.

How to use BULK INSERT when rows depend on foreign keys values?

Another tool in the MSSQL platform is SQL Server Integration Services, a more robust ETL tool. You're describing a scenario where the Lookup Task really shines. SSIS Lookup Task



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why