What is the best way of storing the character's inventory (consisting of each item having a value for type and quantity). The only methods I can think of is to use the "text" type of field then parse the value from that whenever the inventory is loaded. Is there a better method or data structure?

  • \$\begingroup\$ can you just give an overveiw about your game? is it going to be browser-based or is there going to be client application? how many client may connect to your server? what language are you using server side? \$\endgroup\$
    – Ali1S232
    Commented Jun 4, 2011 at 14:18
  • 3
    \$\begingroup\$ I'd say "text" is the worst choice. Build up relations between "item" and "player" tables... overall, this is probable better asked over at: dba.stackexchange.com \$\endgroup\$
    – bummzack
    Commented Jun 4, 2011 at 14:40
  • \$\begingroup\$ Thanks for the advice. I wasn't aware of dba.stackexchange.com - obviously that would be a better choice! \$\endgroup\$
    – jSherz
    Commented Jun 4, 2011 at 17:13

1 Answer 1


Read up on standard database design. Specifically normalized forms. An approach would be to have 3 tables:

character having a character_id and other data

items having an item_id and other data (names, weight etc...)

inventory having character_id, item_id, quantity.

A player's inventory could be expressed as "SELECT items.name FROM items, inventory WHERE inventory.character_id = 'THECHARSID'" Of course based on your other questions I'd much more likely suggest using an ORM that handles this for you. Look at Relationships, and backrefs in something like SQLAlchemy.

If you need the concept of inventory 'slots' then that's another column in the inventory table. (IE: Character 32423 has an item of type 832 in slot 0 (The head slot)) If each item has unique stats (Durability/upgrades) Then you can do something like the item table contains the item specific data, and has a link to an item_base column that defines the base stats that all items of that type have in common.

  • \$\begingroup\$ Thanks for the help. I shall look into ORM and SQLAlchemy. \$\endgroup\$
    – jSherz
    Commented Jun 4, 2011 at 17:14
  • 2
    \$\begingroup\$ If you're still deciding which SQL server product to use, be sure to take a look at PostgreSQL (free and open source, which has a community that is heavily populated with optimization nuts) -- since you may need to have multiple servers, you'll probably be interested to know that PostgreSQL now has built-in replication features and has been well-suited to handling large databases in high-demand environments for a long time: postgresql.org \$\endgroup\$ Commented Jun 4, 2011 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .