dbTalk Databases Forums  

Translating a polymorphic idea into a database

comp.databases comp.databases


Discuss Translating a polymorphic idea into a database in the comp.databases forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
GameboyHippo
 
Posts: n/a

Default Translating a polymorphic idea into a database - 10-31-2007 , 05:09 PM






I'm building a database for an application that I'm writing. Because
I can't disclose what this program actually does, I'm going to present
a similar example.

The application has an entity named person. A person has many
vehicles. There are many types of vehicles: airplanes, ufos,
bicycles, cars, etc... Each vehicle has its own unique attributes
that can be unique to each user. I'm wondering how I can easily
represent the data in a database. I want to be able to run a query to
see what all vehicles a person has and then be able to click on a
vehicle and learn the unique attributes that apply to said person.
Here's an example.

Person
Name
Address
City

Vehicles
Type

Car
Transmission
Color
Max Speed

Bicycle
Style
Height

Airplane
Wing Span
Max Occupancy

Now, I want to run a query to see what vehicles Joe has. Once I know
what vehicles he has, I can run queries to get more details on each
vehicle.

What is the "right" way to set this up? I don't want to query every
table to figure out if a person has at least one of that vehicle
type. I may add more vehicles and thus would have to change my query
each time. Any ideas?


Reply With Quote
  #2  
Old   
David Cressey
 
Posts: n/a

Default Re: Translating a polymorphic idea into a database - 11-01-2007 , 07:26 AM







"GameboyHippo" <jasonwthompson (AT) gmail (DOT) com> wrote

Quote:
I'm building a database for an application that I'm writing. Because
I can't disclose what this program actually does, I'm going to present
a similar example.

The application has an entity named person. A person has many
vehicles. There are many types of vehicles: airplanes, ufos,
bicycles, cars, etc... Each vehicle has its own unique attributes
that can be unique to each user. I'm wondering how I can easily
represent the data in a database. I want to be able to run a query to
see what all vehicles a person has and then be able to click on a
vehicle and learn the unique attributes that apply to said person.
Here's an example.

Person
Name
Address
City

Vehicles
Type

Car
Transmission
Color
Max Speed

Bicycle
Style
Height

Airplane
Wing Span
Max Occupancy

Now, I want to run a query to see what vehicles Joe has. Once I know
what vehicles he has, I can run queries to get more details on each
vehicle.

What is the "right" way to set this up? I don't want to query every
table to figure out if a person has at least one of that vehicle
type. I may add more vehicles and thus would have to change my query
each time. Any ideas?

There are some excellent websites that deal with the design of tables to
represent a generalized entity like vehicle, together with many specialized
entitites like cars.

A web search on "generalization specialization relational model" should
find a lot of them. I particularly recommend the one at U Texas, although
it is being archived. But there are others.







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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.