If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Rokie with a design problem...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-07-09, 20:32
Calvin256 Calvin256 is offline
Registered User
 
Join Date: Jan 2009
Posts: 2
Rokie with a design problem...

Hey Guys,
First of all thank you very much for at least and up to this point show some interest in helping me out ! lol...
I'm trying to design a DataBase but I'm not the best when it gets to designs, so please if you're gonna help out, pretend that you're talking to a 3 years old kid ! lol
Here's the scenario/diagram:

Company Name:
A
B
C

Cities where the compnay's operate:
aa
bb
cc

Services that the companies provide:
1
2
3

The posible results

Company A is in aa bb cc and provides in aa 123 in bb 1 and in cc 13


They way that this is gonna work is the following a comany is gonna register with all their info. ONce that's done is gonna have to list all the cities where this company operates, on submit, the next page will display the list of cities and check marks to specify which services are provided on each of the cities.
Therefore, there will be many companies, operating in different cities some of them on the same city and each company provides certain services according with the city. Therefore there will be more then one company operating in the same city as other companies and offering the same services as the other companies.

I hope this was clear enough, this many to many relationships are killing me...
Once again thanks for all your help and support !
Reply With Quote
  #2 (permalink)  
Old 01-08-09, 09:33
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Companies (CompanyID, CompanyName)
Cities (CityID, CityName)
Services (ServiceID, ServiceName)
Locations (LocationID, CompanyID, CityID)
LocationServicies (LocationID, ServiceID)
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #3 (permalink)  
Old 01-08-09, 10:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Companies (CompanyID, CompanyName)
Cities (CityID, CityName)
Services (ServiceID, ServiceName)
Locations (CompanyID, CityID)
LocationServices (CompanyID, CityID, ServiceID)

the Locations table is probably not required, since a company that offers no service in a particular city can rightfully be deemed not to be operating in that city
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 01-08-09, 10:32
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
I have a question gentlemen.

If the below requirement:
Quote:
Originally Posted by Calvin256
each company provides certain services according with the city.
was instead:
Quote:
Originally Posted by Calvin256
each company provides its full repertoire of services to each city it serves
Would you still have proposed the same designs. If not, why not?
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #5 (permalink)  
Old 01-08-09, 10:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
no, because i can get the desired result with a CROSS JOIN
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 01-08-09, 10:41
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Do you mean the following design:

Companies (CompanyID, CompanyName)
Cities (CityID, CityName)
Services (ServiceID, ServiceName)
Locations (C
ompanyID, CityID)
CompanyServices (CompanyID, ServiceID)


And then cross join Locations with Company Services?
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #7 (permalink)  
Old 01-08-09, 10:43
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Quote:
Originally Posted by r937
Companies (CompanyID, CompanyName)
Cities (CityID, CityName)
Services (ServiceID, ServiceName)
Locations (CompanyID, CityID)
LocationServices (CompanyID, CityID, ServiceID)

the Locations table is probably not required, since a company that offers no service in a particular city can rightfully be deemed not to be operating in that city
What? No harping about the surrogate keys?
But the Locations table probably WILL be required, to store attributes about the location. Plus it helps in maintaining relational integrity in the LocationServices table by preventing services from being specified in cities where the company does not operate.

Quote:
Originally Posted by pootle flump
I have a question gentlemen.

If the below requirement:was instead:Would you still have proposed the same designs. If not, why not?
No, because then the service is an attribute of the company, not an attribute of the company location.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #8 (permalink)  
Old 01-08-09, 10:44
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Quote:
Originally Posted by pootle flump
Do you mean the following design:

Companies (CompanyID, CompanyName)
Cities (CityID, CityName)
Services (ServiceID, ServiceName)
Locations (C
ompanyID, CityID)
CompanyServices (CompanyID, ServiceID)


And then cross join Locations with Company Services?
No, you don't want to cross join to the Services table unless every company offers the same services.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #9 (permalink)  
Old 01-08-09, 10:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by blindman
What? No harping about the surrogate keys?
it was there, just below your level of consciousness


Quote:
Originally Posted by blindman
But the Locations table probably WILL be required, to store attributes about the location.
as i understood the spec, locations = cities
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 01-08-09, 10:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by blindman
No, you don't want to cross join to the Services table unless every company offers the same services.
which is why you would cross join to the CompanyServices table as pootsie suggested
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 01-08-09, 10:53
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Yes - you are right, with that design you would join on companyid.

The reason I asked is that I believe both designs were in BCNF even with that requirement change, but not 4NF. Both your changes, as I understand them, put the design into 5NF. I've thought for a while that 4&5NF problems actually come about from incorrect entity selection in the early stages of db design, and these errors are not rectified by just following the normal forms to 3NF.
I've had, however, a sneaky suspicion that the wiley old experienced modellers would spot the error without explicitly referring to multi-valued dependencies. I just saw an opportunity to test this.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #12 (permalink)  
Old 01-08-09, 11:09
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
error? what error? i spotted no error, except that stupid surrogate key that blindman invented

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #13 (permalink)  
Old 01-08-09, 11:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
p.s. yeah, it's not a CROSS JOIN, is it -- it's a join on only one of the two PK columns

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #14 (permalink)  
Old 01-08-09, 11:13
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Quote:
Originally Posted by r937
error? what error? i spotted no error, except that stupid surrogate key that blindman invented
Had I only thought to patent it, I would be a rich man today.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #15 (permalink)  
Old 01-08-09, 11:20
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
I mean that the solutions to the original question were in 5NF. When I changed the criteria they were only BCNF. This is the 'error' I meant. Yet both of you decomposed the relation in response to the change, thus putting the model back into 5NF.
As I recall both of you claim to normalise to 3NF only. I thought your responses were interesting.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On