1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Subtype tables or all in one table

Discussion in 'MySQL' started by quickgivemesomeanswers, Sep 20, 2012.

  1. #1
    Hello, I'm having a problem with my Travian-type browser game database design. I can't decide should I use subtype tables or not. I have the Unit class which contains all the variables required by units like infantry, ships, planes, ground vehicles, merchants, spies, etc..
    db_without_unittype.jpg

    Is this a good way to make the Unit table or should I use subtypes and create new table for every unit type?

    Every unit has it's own special attributes. For example: merchants don't have attack or defence, only ships can move at sea, ships can move only at sea, tanks can destroy buildings, planes can move both sea and ground and so on...
    So I thought maybe every Unit type needs it's own table like in the image below. I couldn't fully understand that subtype thing but this is what I came up with:

    db_with_unittype.jpg

    I have never needed anything like this so I don't know which one is better. So which one should I use?
     
    quickgivemesomeanswers, Sep 20, 2012 IP
  2. WeddiGo

    WeddiGo Greenhorn

    Messages:
    40
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    18
    #2
    hmm...that's an interesting one, from the point of extensibility the subtypes are good as if you add a new unit type in the future that has an attribute that doesn't exist it won't affect the main table, it all stays self contained.
    I would look at this from an object oriented way and say that if you use subtypes and code classes for specific units you won't make a mistake
     
    WeddiGo, Sep 22, 2012 IP
  3. quickgivemesomeanswers

    quickgivemesomeanswers Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, of course. Thank you WeddiGo :)
     
    quickgivemesomeanswers, Sep 23, 2012 IP