简体   繁体   English

具有相似属性的多个对象的数据库设计

[英]Database design for multiple objects with similar attributes

I have the following objects and respective attributes in my unity3d game: 我的unity3d游戏具有以下对象和相应的属性:

  1. Lumbermill 木材厂

    • Level 水平
    • Production 生产
    • MaxCap 最大上限
    • StoneUpPrice StoneUpPrice
    • ClayUpPrice ClayUpPrice
  2. Quarry 采石场

    • Level 水平
    • Production 生产
    • MaxCap 最大上限
    • ClayUpPrice ClayUpPrice
    • WoodUpPrice WoodUpPrice
  3. Claypit 粘土坑

    • Level 水平
    • Production 生产
    • MaxCap 最大上限
    • WoodUpPrice WoodUpPrice
    • StoneUpPrice StoneUpPrice

My question is, how should I organize this on my Mysql database? 我的问题是,我应该如何在Mysql数据库上组织它?

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 制作一个名为Buildings的唯一表,并将所有属性作为一列放置,同时还要使用一个user_id来引用相应的用户

  • making a table for each Building with the respective attributes, all of them with a user_id too. 为每个具有相应属性的建筑物创建一个表格,所有属性也都带有一个user_id。

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 你可以做2张桌子

  1. Category: To hold the categories like Lumbermill, Quarry etc 类别:持有Lumbermill,Quarry等类别
  2. objects : with category_id as foreign key 对象:以category_id作为外键

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_object player_object

player_id
object_id

Assuming you have players table like below 假设您有如下的玩家表

players 玩家们

id
name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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