I’m developing an online website (using Django and Mysql). I have a Tests table and User table.
I have 50 tests within the table and each user completes them at their own pace.
How do I store the status of the tests in my DB?
One idea that came to my mind is to create an additional column in User table. That column containing testid’s separated by comma or any other delimiter.
userid | username | testscompleted 1 john 1, 5, 34 2 tom 1, 10, 23, 25
Another idea was to create a seperate table to store userid and testid. So, I’ll have only 2 columns but thousands of rows (no of tests * no of users) and they will always continue to increase.
userid | testid 1 1 1 5 2 1 1 34 2 10
Your second option is vastly preferred… your first solution breaks normalization rules by trying to store multiple values in a single field, which will cause you headaches down the road.
The second table will not only be easier to maintain when trying to add or remove values, but will also likely perform better since you’ll be able to effectively index those columns.