I am creating a light RPG game where a character is able to equipment a weapon, an armor and 2 accessories slot. Here's one possible solution:
equipped_equipment(<characterid>, <equipmentid>, <slotid>)
slot(<slotid>, slotname)
equipment(<equipmentid>, equipment_name, equipment_script_name)
So, to find out what weapon the character is equipping, I could do
SELECT equipmentid, equipment_name FROM equipment e, equipped_equipment eq
WHERE e.equipmentid = eq.equipmentid AND eq.slotid = 'weapon' AND
eq.characterid = 1
But how does this compare to something a schema like this?
equipment (<characterid>, weapon_slot, armor_slot, accessory1_sot, accessory2_slot)
Of course, using the three tables above (which is somewhat normalized - I could probably separate out equipment_name and put in into an equipment_details table or some sort) it allows me
- Add new slots easily
- Avoid blank entries (...anything else I may have missed out)
But the second, non-normalized solution allows me to get the IDs of all the equipment with one query, and adding a new slot is simply adding a new column. Which one is better in the long run? Suggestions and improvements welcomed!