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 > Database Server Software > MySQL > Table Design

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-12-11, 08:19
tpynegar tpynegar is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
Table Design

Hi,

I've got several tables that have common data in them. I'm coming from an object orientated programming background so i've made a "parent" table with the common fields and then setup a relationship between it and the "child" tables. I'm thinking this may not be the optimal design for database's as your always going to need to get two tables when you interact with the data. Can anyone give any feedback on this issue as from a design point of view it's cleaner to have them separated up but that's the only reason i can give to do it that way.

Thanks,
Tim.
Reply With Quote
  #2 (permalink)  
Old 11-12-11, 20:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
could you give some specifics?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-13-11, 14:49
tpynegar tpynegar is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
sure

table : coins_transaction

fields :
id
created
coins

table : coins_tranactions_membership

fields :
coins_transaction_id
membership_type_id

table : coins_tranactions_purchase

fields :

coins_transaction_id
item_id

So i'll never access "coins_transactions" directly but there are multiple other tables that also have a foreign key to coins_tranactions to represent different types of transactions.

Thanks,
Tim
Reply With Quote
  #4 (permalink)  
Old 11-13-11, 21:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
i'm afraid i don't see the issue

possibly because i don't understand your coins_transactions table

every transaction has a coins column, but what the heck is that? how is "coins" a transaction?

perhaps you could illustrate the issue by showing what the single-table version of this schema would look like
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-14-11, 05:45
tpynegar tpynegar is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
Ok i think the table names i've used have been misleading for you.

Table : Animal
Fields : Id, Name, NumOfLegs

Table : Dog
Fields : Id, AnimalId, IsCarnivore

Table : Rabbit
Fields : Id, AnimalId, HasFloppyEars

So we've got three tables. In object orientated programming you'd have a parent class "Animal" and then two sub class's "Dog" and "Rabbit". Should i in my database schema also have three tables as above or should i have two tables like this

Table : Dog
Fields : Id, Name, NumOfLegs, IsCarnivore

Table : Rabbit
Fields : Id, Name, NumOfLegs, HasFloppyEars

Thanks,
Tim.
Reply With Quote
  #6 (permalink)  
Old 11-14-11, 05:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
looks to me like you can have just one table, for animals

which way do you prefer?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 11-14-11, 09:55
tpynegar tpynegar is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
For sure in the case of the animals your right it would be better off in a single table however this isn't a real world example as in i was just showing where i was coming from in my thinking.

So the original question was if it's not possible to combine all into one table then am is there a performance penalty on having the separated out tables in mysql or is it so insignificant that i can do what i've done at the moment and separate them out so as to have a cleaner design.

Thanks,
Tim.
Reply With Quote
  #8 (permalink)  
Old 11-14-11, 10:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
whether you use the supertype/subtype model is determined by the requirements of the actual situation

i can't help you if you post stuff that "isn't a real world example"

if you want more info, search on supertype/subtype
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 11-14-11, 11:29
tpynegar tpynegar is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
Thanks for the info.
Reply With Quote
Reply

Tags
design

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