1

I have three tables in my Database:

Customers 
---------- 
Id
Name

Addresses
----------
Id
Description
CustomerId

Orders
----------
Id
Description
CustomerId
DeliveryAddressId

I'd like to make sure that every Address referenced by DeliveryAddressId in the Orders table belongs to the Customer referenced by CustomerId.
How can I model this?

1

I recently answered a question just like this one here:

How to structure Tables with changing status without duplicating data

You have two options, create the foreign key from Orders using both the AddressId and CustomerId or remove the CustomerId entirely from the Orders table as you can obtain it through the relation anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.