I would go with option 1. And, in fact, I would have two new tables: a table for Race and a table that maps classes to race, which I would call something like ClassToRace. ClassToRace would just have two columns, a ClassId column and a RaceId column, which are foreign keys into the Class and Race tables, respectively. The Race table would have a RaceId and whatever other information is relevant to races (RaceName, stats, etc).
The Class table now wouldn't have any Race column at all. If you want information about the races a class supports, you would have to query the ClassToRace table to get all the rows that match ClassId, which will give you the RaceId of each race that ClassId supports.
I already have a Race table so this is why I thought it would be the most correct way to relate the two.
It won't display as nicely as the snippet you posted in the SQL program, but is that really going to matter? It seems more likely to me that all you really want is the information, which your application will use as it sees fit. And you application can display the information however it likes. You shouldn't be making database design decisions based on how SQL displays the information, because that's largely irrelevant to your needs.
At this point I am still in the process of converting from CSV files dumped from spreadsheets. First I am reading the CSV file and then dumping from sqlite3 as an SQL script so that I can edit the definitions and then read them back in as complete tables.
I'm thinking the database is essentially static while my program is running (I have a main-memory array-based database system for in-game entities). But as it is a work in progress I will still be making changes to the database outside of the application.
So, is this a bad thing? I wanted a more regularized representation than a spreadsheet. And it's more natural for me to be able to edit database files from the command-line.
There is a set of 'best practices' for architecting databases, called Database Normalization. You don't necessarily have to follow all of the guidelines, but at least it will give you some ideas and insight that you can apply if you want to.
Thanks for this. SQL has been harder for me to learn than programming languages because it seems like resources are less centralized, so more resources on general design topics are great for me right now.
This has terrible performance. It is an unindexed query. This means that you are reading your entire table every time you retrieve a line.
select * from Class where Race like '%Elf%';
If you ever want to make the "who is an elf" query, you should definetly normalize your database.
Is it going to matter if a table has only between 3 and say, 500 rows?
Edit: The database is more for character creation. Player chooses a Race, next screen might list the Classes that are available to that race. But this database is not the in-game entity database.
Edited by PrestoChung, 14 December 2013 - 02:20 PM.