| |
|
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.
|
 |

07-28-09, 02:40
|
|
Registered User
|
|
Join Date: Jul 2009
Posts: 7
|
|
|
How to handle poli-morphism using MySQL
|
|
Friend, I have a challenge I need your help with...
We use poli-morphism with Java classes and I need to duplicate this with a database design... let me explain...
Lets assume:
- we have customers
- customers can either be rich or poor
- we want to store different details for rich and poor customers; i.e.for poor customers we may want to store information about payment problems, unpaid debt, etc. For rich customers we may want to store details about their assets and buying patterns...
- both rich and poor customers buy products
What is the best design you can think off? We currently use MySQL.
Thanks
Josh
|
|

07-28-09, 02:51
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
|
Originally Posted by joshfolgado
What is the best design you can think off?
|
supertype/subtype
do a search on that for more information
|
|

07-28-09, 09:44
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
|
|
|
|
Are you a charity?
Just delete the poor customers. Makes things simpler, and increases your margins at the same time.
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|

07-30-09, 17:12
|
|
Super Moderator
|
|
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
|
|
You could migrate to PostgreSQL and use table inheritance.
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert
|
|

07-30-09, 17:34
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
|
Originally Posted by loquin
You could migrate to PostgreSQL and use table inheritance.
|
this is an inappropriate comment, especially for a moderator
at least, that's what i was told when i made a comment like that (which partly explains why i'm no longer a moderator)
you didn't even include a smiley!!!
|
|

07-30-09, 17:41
|
|
Super Moderator
|
|
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
|
|
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert
|
|

08-02-09, 10:37
|
|
Registered User
|
|
Join Date: Jul 2009
Location: Michigan
Posts: 125
|
|
Have a customer table with a unique ID for each customer and a flag to say if he is a rich or poor customer.
Have a rich customer information table that contains the customer ID and the attributes you want to store for rich customers.
Have a poor customer information table that contains the customer ID and the attributes you want to store for poor customers.
|
|

08-02-09, 15:18
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
nice one, mark
so, basically, a supertype/subtype table structure, yes?

|
|

08-02-09, 19:59
|
|
Registered User
|
|
Join Date: Jul 2009
Location: Michigan
Posts: 125
|
|
If you say so. I have been doing database design a long time and have seen a lot of buzz words come and go. Thirty years ago we used to call design as being a master with multiple detail tables.
|
|

08-02-09, 20:52
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
|
Originally Posted by MarkATrombley
Thirty years ago we used to call design as being a master with multiple detail tables.
|
interesting that you should say that, because "tables" did not hit the mainstream for another decade or so, when relational databases were introduced (i started with DB2 in 1987)
i'm sure you were using master/detail concepts, maybe with IMS?
i also used the same concepts, but they were called owner/member in CODASYL (the standard that preceded relational databases)
|
|

08-02-09, 21:14
|
|
Registered User
|
|
Join Date: Jul 2009
Location: Michigan
Posts: 125
|
|
Thirty years ago I was working on a DEC PDP-8 with 64K of memory, programming in Dibol (DEC's version of Cobol). We used files with indexes back then, not a relational database. The concepts were the same regardless. I pay a lot more attention to storage concepts than I do the buzz words.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|