-1

i have four tables company,subcompany,form and cargo each company contains several subcompanies and each subcompany contains forms and each form contains cargoes

i need queries to get fomrs of a company, forms of subcompany, cargos of a company, cargos of sub company

my question is Which relationship is better? i choos secound one because i think its easier to query and faster.

  1. add only relations between

    Company ----> SubCompany -------> Form ------> Cargo Image1

  2. add relation between company and all three tables, relation between subcompany and two other tables, and relation between form and cargo. Image2

Saeed Taran
  • 376
  • 2
  • 14
  • The first one is better. The second one contains redundant information, which is generally a bad thing, although sometimes this *denormalizing* is done when it is really needed for speed, but you probably won't need it. A normal database doesn't have problems with 3 joins. If it does, improve it in other ways while keeping the relations normalized. – GolezTrol Aug 30 '14 at 09:58

1 Answers1

0

It seems that Form and Cargo have a composition association and SubCompany and Form also have a composition association thus there should be a one to many relationship between them. So far your number 1 design seems better but the question is what's the relationship between Company and Form ? If a SubCompany can have forms will a Company can have Forms also ? (Having Forms is a feature of a Company or its SubCompany?) If Company can't have Forms itself then number 1 seems to be a reasonable design but if it can then may be you should change it a little bit some thing like this :

Company has a one to many self relation (Sub Company)
Company has a one to many relation with Form
Form has a one to many relation with Cargo   

In this design there's no individual entity for SubCompany each Company that has a parent Company is a SubCompany of that Company

Community
  • 1
  • 1
Beatles1692
  • 5,214
  • 34
  • 65
  • no a company cant have forms, but there is alot of companies that are getting report of their subcompany forms every 10 secends, so i decide to add a relationship between company and form to query and show forms of sub companies to companies faster, but it seems i was wrong – Saeed Taran Aug 30 '14 at 10:22
  • Perhaps you'd better have a view that shows each form for each company according to its sub companies. – Beatles1692 Aug 30 '14 at 10:37