-3

I have three tables

1) products

with following columns:

product_id, product_cat, product_cat_brand, product title, product_price, product_image

2) product_Category

with following columns

cat_id, cat_title

3) product_Brand

with following columns:

brand_id, brand_title

Question???

so my question is: which table will receive the foreign key of which other table? or in other words how i can make relations between these tables..

Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30

2 Answers2

0

Products table : ProductBrandID // because a product can be belongs to only one brand. For example : A phone can be belongs to Samsung or Apple.

You need to create a new table Categories_To_Products productID, categoryId // because a product can be linked in more than one category. For example : A phone can be linked in categories (phones, touch phones, electronics, communication devices)

Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
  • Thanks for your feedback Naveed ramzan. but its not like that.. one product (like samsung-s4) should belongs to to only and only one category (like mobiles). on the other hand, one category(like mobiles) should belongs to many categories (like samsung, iphone, nokia etc). so there is one to many relationship between them and catagory_id will move to product table. my confusion is about brand table. will brand primary key will go to product table or category table? – irtza sahir Jul 18 '16 at 06:33
  • If products have only 1to1 relation with category then you can add both foreign keys in products table like brandId, categoryId. – Naveed Ramzan Jul 18 '16 at 06:35
0

if you want to do the E-R ,than you have to tell us what relations do you want between your tables,we have your tables but its difficult to guess what do u want to do with them . If you tell ,what relationships do u need i can hel you . Thanks :)

  • yeah, sure, i am confused about the relation of brand table. will we make it relation with product table or category table? if i make its relation with product table then it will be one to one. and if i make its realtion with category table it will be one to many with middle/junction/associate table so what relation will be better? – irtza sahir Jul 18 '16 at 14:16