[MySQL] Proper way to do player statistics?
#1

Hello, everybody well i am working on my server right now and i am wondering what would be the smartest thing for me to do the statistics. As of know i am putting all player statistics, such as cash, bank money, fighting style etc. in Users table. In all i have 34 fields right now for the Users table. I am wondering now, is it worth just creating a different table for stats something similar to what a gun saving system looks like? So the stats table would include User ID, User nickname, stat ID and the statistic itself in there and that would be for every player. Or is it just better for me to keep on piling up on the User table, with amount of fields reaching almost 100 or more? And yes i have read, threads on database normalization, but just want some opinions on what is the best thing dealing with statistics. Thank you.
Reply
#2

Mehh, my personal opinion is having the statistics in the same table, however some things such as a player being banned should be in a different table.
I'd say, if you're scripting a kind of big system then sure, create a new table for it but other than that, use the same table for the statistics.
Reply
#3

If you're planning to create another table, only put the UserID in there, along with Stat ID and the value.
The user's name should already be in your Users table.
There is no need to copy it to every other table where a UserID is located, a player's name should only exist 1 time in your entire database.

If there are many statistics, you might find it useful to use another table for it.
If it's less than 15 or so, just include them in the Users table.
Reply
#4

Place all player stats on a single table like everything that is written in your enums.

Even better every new enum that needs saving in MySQL(since some doesn't isn't essentially needed saving on the database) needs different tables. So that when you're trying to look something related to a certain enum you will find it.

Now the banning like he is saying, there are two ways of banning an I.P ban and a character ban. If you ban a character just use the single database but if you have an I.P ban thing make a single table that'll save all the I.P's that got ban.

With that said I think you understand what I mean
Reply
#5

Only store things in the User table that apply to every single user without exception. Storing a bunch of zeros or nulls is pointless. I will usually limit the amount of fields in a single table to a maximum of about 30 before it becomes unmanageable. Also make sure that you don't store things that can be derived or calculated, e.g. if you store birth date then don't store age.

I don't know what your setup is like so I can't give any concrete advice at the moment.
Reply
#6

Here i have taken a picture of part of my Users table and my Weapons table. So what i am thinking is doing a similar thing with statistics, of a player as with weapons. Because i plan on having a lot of statistics, like time spent in a vehicle, boat, train, kills, wanted time, evade time etc.. The only issue that i can think of, aren't there going to be many rows? Or long loading times if i do it similar to the weapon system? Also for Achievements should i also have a different table if i plan to have a couple hundred of achievements?

Here's the Users table(for now):

Here's the weapons database, that i want to use the style of for statistics of each player.


What do you guys think? And i think id like to start putting like stamina, fight style and stuff like that into a new table.
Reply
#7

Everything that is related to user keep in the same table. Kills deaths etc.. all stats.
Reply
#8

Quote:
Originally Posted by Astralis
Посмотреть сообщение
Everything that is related to user keep in the same table. Kills deaths etc.. all stats.
Won't it lag tho while loading or saving, if i have over 100 fields??
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)