How to insert excel data into foreign key table

时间:2015-05-24 21:41:09

标签: c# asp.net sql-server-2008 oledb sqlbulkcopy

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.

1 个答案:

答案 0 :(得分:0)

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