Re: modeling either/or relationship...



Murdoc wrote:

> -CELKO- wrote:
>
>>
>> Now start hiding all this stuff in VIEWs immediately and add an INSTEAD
>> OF trigger to those VIEWs.
>
> All this seems slightly over-complicated for what appears to be a simple
> issue. Why create 7 tables, when 1 will do?
>
> Vehicle -> [#vin, vehicle_type, door_count]


This will work if and only if all there is to a car is a unique vin, a
vehicle_type and a door count, and vin is a primary key for every car.

Both assumptions hold in this example, but both are usually violated in the
wild.

What if you need to model a class of cars without vin (a variant of this
shows up often in employee databases that take SSN as a primary key and
suddenly have to deal with foreign employees)? What if there are duplicate
vins in different contexts? Two license plate numbers from different
countries for example may be identical for two different cars, maybe there
is a similar thing with your vins. Maybe you need to model vehicles from a
country where the laws use two numbers to identify chassis and engine, and
one single vin is meaningless? Then your domain may still consider a
vehicle an entity, but different vehicle_types may have different
requirements for primary keys. That is a tricky yet frequent case in
real-life databases.

The other assumption is weak, too. Your cars will have more than one
attribute. The set of attributes for a SED and a SUV are almost guaranteed
to differ. You may get away with one broad table that contains a superset
of all possible attributes of all vehicle types, but then again, Murphy's
Law says you won't.


> In you example, how would you structure the query to find a listing of all
> 4DR cars currently in your database (assuming that both Sedans and SUVs
> can be 2-door and 4-door vehicles)?


As Joe wrote, you wouldn't. You would hide all this complexity in VIEWs.




--
Ernst-Udo Wallenborn
.



Relevant Pages

  • Re: NBC: Oligopoly And the Fall of the American Automobile Industry; by Thomas Lifson
    ... fact that the market share for 2008 for the Big 3 is 47.5% of the US market, with the 3 biggest Japanese firms at 34.3%. ... because they are not making the cars which a majority of Americans want to buy. ... Now, you can say that those cars might not have had the quality reputation than the Japanese brands and that, in general, the Big 3 have always marketed their economical vehicles as "economy" vehicles but that's the only way they could sell them. ...
    (rec.music.artists.springsteen)
  • Re: First China Made Cars to Invade the US
    ... International and Guang Ming are showing their vehicles, ... Five manufacturers from China are showing cars here this year, ... Toyota does not expect its car to compete directly with the Nano. ... Interest Fades in the Once-Mighty V-8 ...
    (soc.culture.china)
  • Re: The ending
    ... It's a mistake to say that banks produce nothing. ... But there is an inherent problem with letting the market fix the market... ... a sufficient number of small fuel-efficient cars to offset the large luxury cars, SUVs and trucks which are their real bread and butter. ... The Big 3 can sell large expensive vehicles at a profit but their small cars can't compete with offerings from Japanese and European producers, who of necessity, have been making excellent small gas-misers for decades. ...
    (comp.sys.ibm.pc.games.rpg)
  • BIG 3 BAILOUT
    ... Motors never again have to return to Washington D.C. for a handout? ... Motors do not just build cars and trucks. ... they create, design, ... and designing a variety of vehicles for a variety of applications; ...
    (alt.politics)
  • Re: "Who Killed the Electric Car?" opens July 14th
    ... how limited the cars were, ... sales of zero-emissions vehicles by 2003, ... wind-, solar-, and trash-powered plants, as the Cape Wind project has ... cars can made more efficient use of fuel through ...
    (rec.arts.sf.fandom)