Sign in to follow this  
alucardeck

[web] Database doubt

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this