0

I am trying to figure out the best way to store some data in my database. I plan on joining 3 different tables.

users table
fighters table
moveset table

In the fighters table I have a row for 'moveset' in which I am trying to figure out a way that move_id's from the moveset table can then be associated within the fighters table under the moveset row so each fighter can list a bunch of moves that belongs to them.

Ex.

fighters table has

fighter_id,
fighter_name,
moveset

moveset table has

move_id,
move_name,
move_damage

Multiple move_id's need to get put in the moveset row in the fighters table.

Any help on how to set this up properly in mysql?

1
  • Do you have the concept if a "set of moves" that have reasonable reuse? Like a "move profile" that could be used to assign to one or more flights as a single thing? Commented Jul 28, 2013 at 0:21

1 Answer 1

2

You need a "many-to-many" relationship.

To store this, the best way is by creating an association table, which has the key if both tables being related:

fighter_moves
-------------
id
fighter_id
move_id

You can even add other non-key columns, called assoiation data, that describe the relationship. For example, speed to define how fast the fighter does the move.

Sign up to request clarification or add additional context in comments.

6 Comments

So basically create 4 tables. The 3 I have a above for details and 1 to tie them all together by id?
Yes. It's the only (sane) way to represent a many to many, which is what you have. Your design fine.
But if I have over 500 moves and over 1000 fighters, and each fighter has 50-100 moves, that could get problematic, no?
No, it will be ok. Another option, if you don't need to have a fighter_moves id column, is to make fighter_id and move_id a compound primary key of the fighter_moves table (this will act as a unique constraint + index for free).
So then no matter what I would have to associate each move to each fighter over and over rather than have an "array-like" or something similar in MYSQL to link multiple moves to one fighter in a database?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.