简体   繁体   中英

Database design for multiple objects with similar attributes

I have the following objects and respective attributes in my unity3d game:

  1. Lumbermill

    • Level
    • Production
    • MaxCap
    • StoneUpPrice
    • ClayUpPrice
  2. Quarry

    • Level
    • Production
    • MaxCap
    • ClayUpPrice
    • WoodUpPrice
  3. Claypit

    • Level
    • Production
    • MaxCap
    • WoodUpPrice
    • StoneUpPrice

My question is, how should I organize this on my Mysql database?

I thought already of:

  • making a unique table named Buildings and placing all attributes as a column, also with a user_id that refers to the respective user

  • making a table for each Building with the respective attributes, all of them with a user_id too.

I didn't learn about database in my college yet, so I would really appreciate any help. My English is not one of the best, but I tried to make myself as clear as possible.

Thanks for now :)

You can make 2 tables

  1. Category: To hold the categories like Lumbermill, Quarry etc
  2. objects : with category_id as foreign key

Category

id
name

objects

category_id
Level
Production
MaxCap
StoneUpPrice(can be null for non relevant category)
ClayUpPrice(can be null for non relevant category)
WoodUpprice(can be null for non relevant category)

EDIT prior to your comment

You can make seperate bridge table like player_object like below

player_object

player_id
object_id

Assuming you have players table like below

players

id
name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM