'How to enforce integrity for orders?

If a user can have multiple addresses and phone numbers, is it possible to design the database in such a way that I can enforce integrity between data?

For example:

users(id,name)
addresses(id, description, user_id -FK to users)
phones(id, description, user_id -FK to users)
orders(id,address_id -FK addresses,phone_id - FK to phones)

How can I be sure that in the orders table I won't accidentally insert a record with user1 address and user2 phone number?

I'm sorry if this was asked before but I don't know how to search for this situation.



Solution 1:[1]

Where is the Orders table? It will have columns user_id, address_id, and phone_id.

For data entry, if a known user calls in an order, then the UI brings up the existing addresses and phones for that user. The order-taker can quickly click on them. Or the user can say to use a different address. Then the UI assists in adding a new address for that user.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rick James