Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>The alternative is to move all stats into separate tables. For example, items stats with be in a "item stats relation" table, with IDs linking into the item and stat tables.</p> </blockquote> <p>This is the correct method of dealing with the business rules.</p> <blockquote> <p>If I add a new item, rather than just inserting a single row into the item table, I now have to insert many more rows into the "item stat relation" table to include all of the stats it needs.</p> </blockquote> <p>Only if that item actually uses the stat. It allows an item/etc to have 0+ stats associated, and means that you would never have to update the data model for every new stat to add a column.</p> <p>There's no performance benefit when you risk bad data. What you would make, will be eaten by the hacks you have to perform to get things to work.</p> <blockquote> <p>...use MySQL functions over multiple items (i.e. to add up the "Strength" of all items owned by a Player), if some of those items don't even have a record for that stat...</p> </blockquote> <p>Use:</p> <pre><code> SELECT IFNULL(SUM(t.value), 0) FROM PLAYERS p JOIN ITEM_STAT_RELATION itr ON itr.player_id = t.player_id LEFT JOIN STATS s ON s.stat_id = itr.stat_id WHERE p.player_id = ? AND ... </code></pre> <p>The LEFT JOIN is used to indicate that a supporting record may not exist, and the IFNULL is meant to handle such a situation because it's value would be null. SUM can handle NULLs - it interprets the value to be zero.</p> <blockquote> <p>...serializing all stats into a VARCHAR or TEXT column.</p> </blockquote> <p><strong>Don't do this</strong><br> Concatenating a list of stats will be a pain to pull out details if you want to report on a specific stat or group of stats. Due to character limits, it runs the risk of not being able to store every stat within a single column.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload