Jump to content
  • Advertisement
Sign in to follow this  
alucardeck

[web] Database doubt

This topic is 3081 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, my question is about how to create the best relationship between tables (MySQL). i will give an example: I have an entity 'Hero' and one called 'Hability' and one called 'Equip' ok, a Hero can have until 10 Habilities (in no specific order) and a Hero also can have 7 equip slots. So what is the best way to create the tables? Table: Hero Table: Hability and then a third Table: Hero_Hability for the ids. or Table: Hero Table: Hability so in Hero table, i would have 10 columns beign the specific 10 slots for habilities.. linking the foreign keys from hability table.. hab_1_id, hab_2_id, hab_3_id .. etc.. the same question for the relation between Hero and Equip tables. but in this case i would need to save the position of the equipament in the slots, because i need to know in what part of his body the item is equipped. so i would need a column called 'position'. any idea what would be the 'most correct' way to link both tables? remembering its NOT a '1 to *' relationship... Thanks =]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
remembering its NOT a '1 to *' relationship...
To my knowledge SQL does not have a way to enforce this constraint. Just do it in your code.

Share this post


Link to post
Share on other sites
I would do it like this:

Hero
- id
- name

Equipment
- id
- description

HeroEquipment
- heroId
- equipmentId
- position

Position might optionally be changed to another foreign key pointing to a table containing the different body parts.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!