I am creating a database for an app that helps learn a language. I need to create tests that vary by section (test for grammar, about text, etc), topic and level.
USER
id (pk, autoincrement)
name
last_name
email (unique)
level_id
password
LEVEL
id (pk)
description
SECTION_TYPE
id (pk, no autoinc [to avoid creating a field for level_num])
section_name
TOPIC
?id (pk)
section_id (fk)
level_id (fk)
name
TEST
?id (pk)
topic_id (fk)
num
QUESTION
?id (pk)
test_id (fk)
num
text
has_multi_ans
ANSWER
?id (pk)
question_id (fk)
num
text
is_correct
I have read that using a composite index can facilitate fast search. And searching test by level and topic will be a frequent thing. But in my case a composite index is a unique combination.
I could make it a composite primary key with fields highlighted with tabs instead of creating single primary key id
. Because in the first case I will have to also create composite foreign key. That would almost eliminate the need to create table test, but would be messy.
How should I go about this?
Postgres FK referencing composite PK is a bit different since there are many other dependent fields so a unique single primary key is justified.