waleed bin khalid waleed bin khalid - 11 months ago 40
MySQL Question

what is the better way to store data in mysql table?

Actually i want to save Base Abilities for game. i have two option one is to save a very long string like this [{'baseId':1, 'baseName': 'xyz'},{'//', '//', 'etc'}] or the second option is to save these type of record in multiple rows and column. Or if someone has a better option to do this you can suggest me and thanks in advance. :)

Answer Source

This is a typical object oriented to relational mapping problem.

In short it depends on the ease of READs and ease of WRITES.

If you think that this data is always going to be retrieved as a whole JSON and being written a whole you may want to use MySQL JSON Data Type or even a varchar like type.

Otherwise map the fields to a new table and and store as rows. Here you may be better off with one row representing 1 object instead of complicating futher and spanning the field to rows. Again look as your READ and WRITE use cases with respect to partial or full entity.

Then there is a programming model to consider - which model keeps your code simple and less prone to bug.

The other aspect is the effeciency of storage as well. How many records are going to exist ? The data type affect this e.g. blob types TINYTEXT and LONGTEXT are different when it comes to storage.

All these askects need to be considered.