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 > How to handle poli-morphism using MySQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-28-09, 02:40
joshfolgado joshfolgado is offline
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
Reply With Quote
  #2 (permalink)  
Old 07-28-09, 02:51
r937 r937 is offline
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-28-09, 09:44
blindman blindman is offline
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"
Reply With Quote
  #4 (permalink)  
Old 07-30-09, 17:12
loquin loquin is offline
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

Reply With Quote
  #5 (permalink)  
Old 07-30-09, 17:34
r937 r937 is offline
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!!!
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 07-30-09, 17:41
loquin loquin is offline
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

Reply With Quote
  #7 (permalink)  
Old 08-02-09, 10:37
MarkATrombley MarkATrombley is offline
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.
Reply With Quote
  #8 (permalink)  
Old 08-02-09, 15:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
nice one, mark

so, basically, a supertype/subtype table structure, yes?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 08-02-09, 19:59
MarkATrombley MarkATrombley is offline
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.
Reply With Quote
  #10 (permalink)  
Old 08-02-09, 20:52
r937 r937 is offline
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)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 08-02-09, 21:14
MarkATrombley MarkATrombley is offline
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.
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