sql - Database structure for storing a statement and 4 options with inline images -


i have statement can have multiple inline block images (like mathematical formulaes) , has 4 associated choices (like in quiz) , each 1 of them can have number of inline images well.

i know in naive manner can store html each of them

q_id|ques|number of choices| choice | choice b | choice c | choice d  

or can have question table

q_id|ques| q_contains_image| number of choices| choice | choice id| choice_contains_image| choice b | ....choice c... | choice d ... 

and image table

img_id|q_id/choice_id|image_path 

i still don't know if best way , how second way affect performance if need render question choices in html. don't first way because require hardcoding path within html , html never nice read when see them result of sql query.

i want know method store them along implied costs of using method.

let's normalize data. normalizing data, eliminate redundancy in data , reduce storage needed minimum.

you need join tables @ of information. joining tables relational databases designed do, join tables quickly.

question -------- question id question text  answer ------ answer id question id answer text  correct answer -------------- correct answer id question id answer id  question image -------------- question image id question id question image  answer image ------------ answer image id answer id answer image 

in each of above tables, first id field primary (clustering) key. primary key auto-incrementing integer or long.

any id fields after first field foreign keys pointing table primary key.

in correct answer table, have additional unique index on (question id, answer id).

you don't store html in of database columns. store text or images.

edited answer questions in comments.

should have flag image in question/image table or suggest deduce on basis of getting match or no match image table.

you deduce on basis of getting row or no row image table.

what mean correct answer id. suppose have question choices a,b,c,d , a,b correct. how propose feed data here?

if have more 1 correct answer question, have more 1 row in correct answer table. question id same both rows in example, white answer ids point 2 correct answers.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -