The name may not be entirely correct, but it describes the problem as accurately as possible. There is a field, ShopID in this field I need to make several values, for example: 1, 2, etc. I understand what to do when the field is a foreign key is impossible, but how can I solve my problem? The problem is that this field is in the product information table and the product may be in several stores.

  • four
    or maybe it is worth looking at the relationship of the type of goods - shop Table with fields ShopId & ArticleId . on the basis of which it will be possible to get all the goods in the store, all the stores that have this product. - Bald
  • @Bald i.e. create an intermediate table with these fields? maybe this is really the way out, thanks. - Denis
  • @ Denis Yes, do it. Here the question is not even in the foreign key. In a relational database, they always make a separate table when it is necessary to save several values ​​to a single record. Storing several values ​​of one property directly in one record violates 1-NF ru.wikipedia.org/wiki ... and leads to difficulties in working with such a database - Mike

1 answer 1

I would try to implement this by creating a link table, i.e. tables in which will be id from both tables, for example:

 +------------+---------------+ | ShopId | ArticleId | +------------|---------------+ | 1 | 1 | +------------|---------------+ | 1 | 2 | +------------|---------------+ | 1 | 3 | +------------|---------------+ | 2 | 1 | +------------|---------------+ | 2 | 5 | +------------|---------------+ 

this way getting all the products of a particular store will be reduced to

 select * from table where shopId=@shopId 

and getting stores with a particular position to

 select * from table where articleId=@articleId