Updating SQL Server tables with a foreign key relationship

Eight Stars

Updating SQL Server tables with a foreign key relationship

I have two tables in SQL Server that I need to update. One table contains Customer data, and the other contains Order data. A customer can have any number of orders, including zero. If she does have any orders, then the Order table contains her customerID, along with the orders. In other words:

 

Customers

  CustomerID (unique, auto-insert)

  Name, etc.

 

Orders

  CustomerID

  Order Info, etc.

 

The data I need to load is denormalized, so it looks like this:

 

Name                                    Order

Alex                                       Books

Alex                                       More Books

Rebecca                                NULL

 

. . .and so on. I can load the Customer table without issue. However, I don't know how to load the Orders table, since I need the CustomerID from the Customer table, and I don't have any way to link that back to the denormalized data to find the actual orders. Does anyone have any advice?

Fifteen Stars TRF
Fifteen Stars

Re: Updating SQL Server tables with a foreign key relationship

Hi,
I'm afraid you have to query the customer table after you have finish to insert rows. Then you'll be able to get the id to use in the order table as a foreign key.

TRF

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog