Click to See Complete Forum and Search --> : Data storage in MySQL


Sharsnik
August 11th, 2008, 06:45 AM
Hi, I was wondering what the best way to store dynamic arrays in SQL was. The 2 options I can think off off the top of my head are:

1) create new tables for the items you want stored in the dynamic array and reference by the first table's key values (I.E. I have table CHARACTERS and I want an inventory list of items of dynamic length, so I make table ITEMS and attach each item to the character's name).

2) use a varchar string, with hashed out values of the items. But this would require, in theory, VERY long strings, which might become a burden?

I won't have to access this information too incredibly often, so speed isn't a huge, huge deal. If anything the write time is more important than the read time.

pm_kirkham
August 13th, 2008, 06:56 PM
The first option appears like a normal database design - there is a relation Inventory with tuples (Character, Item). The second option appears like something you'd find on daily ***, though it may be that you're trying to work around SQL's limitations in that you can't have a field in a tuple in a relation which is of a relation type.

But from what you've posted, it doesn't seem any other than a simple one-to-many relation of [ Character ] ---< [ Item ] , and SQL can do that fine.