How to integrate one table from the database to another?

1

Example: A system that records customers, purchases, and products, each in a different table. Having a purchase record that must have the fields:

  • Client: indicates which client has already registered (in another table of the bank) that made the purchase.

  • Products: Selects which product (which is also in another table) sold to the customer.

In addition I should put other fields as date of sale etc, but this is not the case, as I want to know how I do this integration between tables? Catch the record from another table and associate it with a field from a record from another table. I've tried searching for it but I could not find it, if you give me an example of how it would work or what terms I should search I would appreciate it.

I do not want to put too much code in database language, because I do not understand any of this, the banks I create are totally visual, that is, created automatically by Visual Studio.

Details : It should work as follows, when you want to register a purchase, you would inform the date of the sale (that part I know how), the customer who bought it. register in another table then you must search and associate the customer name with your data stored in the other table) and finally the product sold (which also has a record in another table)

    
asked by anonymous 05.07.2015 / 07:09

1 answer

1

The integration between tables is usually done by foreign keys . A foreign key lists a primary key of a table with the primary key of another table. This ensures referential integrity between tables.

For your example, a purchase must relate products to a customer. The ideal would be to have an associative table between products and a purchase, having an additional field, that of quantity. That is, this associative table must have, in addition to its primary key, two foreign keys, one pointing to a purchase and another pointing to the product that belongs to a purchase.

    
05.07.2015 / 07:28