0

Hello Community from a Newbie;

I haven't found anything like this here with the search function so I hope it's not a stupid question . ( And sorry for my bad english ) .

I've planned to do a checklist with checkboxes in it (over 30 I think). I'm now thinking about how to store the status ( check or not checked ) into my SQL Database and read it out .

Plan A : For each Checkbox I'll put a Column in the database, which sounds like an easy way but I think there has to be a better way in sense of Performance

Plan B : like an binary code in a single Column - like 00100 - means that just the 3rd Checkbox is a checked Checkbox . Makes more sense to me but give me a little bit the feeling that it is hard to code especially in case of reading those checkbox list out from SQL again like


if (00100 == 00010) checkbox2.checked;
if (00100 == 00100) checkbox3.checked;

I hope you can help a C# Newbie and give me maybe some other Solutions Ideas.

Thank you All Greetings from Austria

unflores
  • 1,764
  • 2
  • 15
  • 35
Likemike90
  • 43
  • 6
  • 1
    Depends entirely on what the checkboxes store and how they will be used. Which you haven't told us. – Dour High Arch Nov 27 '19 at 22:02
  • I sincerely do not understand this question. Add a question mark for starters. Also what are you trying to achieve? Please rework the question. – panoskarajohn Nov 27 '19 at 22:02
  • While this question is regarding C, similar principles can be applied to C# : https://stackoverflow.com/questions/10493411/what-is-bit-masking – Jon P Nov 27 '19 at 22:07
  • 1
    Plan C ... it's "SQL database" is Relational database ... use 3 tables for this `Ill(id,name)`, `Patient(id, name)`(or Survey/Probe) and finally `IllPatient(IllID, PatientID)` – Selvin Nov 27 '19 at 22:17
  • hmm, it's not about ill and patient but `I'll`, please use f.g apostrophe next time ... any way comment is still valid – Selvin Nov 27 '19 at 22:28

1 Answers1

1

So, there is a lot to unpack here. Basically, you are asking how to structure a database table.

IMHO Plan B is not a road you would like to go down. It will be quite confusing to anyone trying to make sense of it in the future. With respect to the table, it depends on your checklist.

Plan A is too static. Will that list change(grow or shrink)? When you talk about storing checks, you are storing responses. This begs the question how will you be storing the actual questions?

I would probably create two seperate tables, one for questions, and the other for responses.

This may seem a little overboard at first from your perspective but it allows you change your checklist over time.

Modeling-wise my question table might look like this:

table: questions columns: content, order

table: responses columns: question_id, user_id, checked:boolean

unflores
  • 1,764
  • 2
  • 15
  • 35
  • Agree with this approach. One of the most compelling tenants of databases, and coding in general, is that things change. The approach in this answer lets you add or remove questions, or change their order at will. And please don think that storing 30 rows is a performance issue (assuming you are not surveying the planet). Its not, just make sure you create your indexes correctly. – TomC Nov 27 '19 at 22:49
  • thanks , sounds now more logic to me , i will try it out in the upcoming days .Thanks for all the Help – Likemike90 Nov 28 '19 at 20:48