• 13
• 18
• 19
• 27
• 10

# [web] Database doubt

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

## 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 on other sites
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 on other sites
I would do it like this:

Hero- id- nameEquipment- id- descriptionHeroEquipment- heroId- equipmentId- position

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