Best way to add info/description to my items?

Viewed 44

I made a geo game a while back where the player has to guess an item from an image (what I call an item is a SQL row basically) for example the bot sends the flag of the Netherlands, you have to type "Netherlands" to win.

Items can be the flag of a country, a capital city, a french department...

I made an info tab where it would basically give info about an item (ie region, former name, capital city, etc).

What I would like to do is properly save this information. I don't really know if I should store this in files like JSON because I would also like to give stats (Win rate per region, amount of games played per region, etc...).

Also, these elements are not fixed because some items have regions, capital cities or whatever and some don't.

Item examples :

(For a flag

Column Attribute
ID 1
Name United Kingdom
Former name United Kingdom of Great Britain and Northern Ireland
Code GB
Continent Europe
Subregion Northern Europe
Capital city London

...

(For a U.S. State)

Column Attribute
ID 1
Name Arizona
Capital city Phoenix
Largest city Phoenix

...

1 Answers

The both solution (Add all as column and json) are not the proper way.

I think the best design is to have a key-value table.

Create Table tableName (ID INT, [Key] SYSNAME, [Value])

And data will look like:

ID Key Value
1 Name Arizona
1 Capital City Phoenix
1 Largest City Phoenix
2 Name United Kingdom
2 Former name United Kingdom of Great Britain and Northern Ireland

Most valuable benefits: No Extra storage for columns with large amount of rows with NULL value.

Related