1
\$\begingroup\$

So basically I'm new to SQL Servers and for that matter generally to Server Logic and Server behavior. (Used to only work on single player games) OK, so my questions is as followed. Lets take Hearthstone for example every user has a card collection. Now if using an SQL server, I can create tables for the users, I can also create tables for the cards, but how do I combine those? To be more specific my solution would have been to make a new table where the playerid and the cardid is stored with the value of how many of the certain card the player has.

However, my issue with this solution is that, if we assume we have 1000 players and we have like 500 cards then the table will be clustered with entries of same playerid's who have different cards.

Basically my question is: Is there a better solution for this and if not what is the capacity of SQL tables/Servers, like when can i expect a drop off during loading the collection of a player who has all 500 cards for example?

Since I'm new to SQL I might also be having a wrong idea on how to solve this issue, so if there is another solution or I'm missing something I would appreciate if someone pointed me in the right direction.

\$\endgroup\$
2
\$\begingroup\$

Your hunch is reasonable: you'd create a third table, a CardOwnership table or some such, that has (at least) columns for player ID and card ID. You'd probably use a clustered index on the player ID for this table.

While capacity and performance measurements are tricky in a vacuum, it's quite unlikely you'll see any sort of performance issue with only 1,000 players having up to 500 cards. Those are pretty small numbers in the grand scheme of things and you'd likely be fine even if you chose really poor indexes and wrote relatively suboptimal queries to access them.


That said, don't fall into the trap of thinking that your SQL database has to be your backend. In general, you may want to use a database as a long-term storage mechanism but for actual gameplay, you'd probably want an actual server program (written in whatever language you're familiar with) running to arbitrate and validate play sessions. The server would have its own, in-memory data structure for representing the card collection of a player that you eventually persist to a database.

You don't even strictly speaking need a database for this; you could just as easily archive the player information to disk after a game using basic file I/O.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the fast rply. But i have a follow up question even if i have a acctual Server in the end i still need a database to store the collection or is there a possibilty to save the player collection another way (because even if i have a dedicated Server for the game functionality i still need to store the Informationen or am i missunderstanding ? \$\endgroup\$ – GuentherDonner Nov 9 '18 at 13:27
  • \$\begingroup\$ You can just save the collection as a file on the disk. A database is not necessary and in some cases may be overkill. \$\endgroup\$ – Josh Nov 9 '18 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.