2

Here is the scenario: There are teachers who teaches various subjects. Subjects comprises of chapters. There may be more than one teacher teaching the same subjects but have different chapters assigned to them. There are topics, subtopics (hierarchical) inside chapters.

I am concerned with the entities: chapters, topics only. Chapters have properties like teacher_id, subject_id,title, designated_hours. Topics (also has subtopics and subtopics may contain subtopics inside them i.e to say hierarchical). Topic properties are title, teaching_methodology, hours, periods, completion_date.

My proposed structure:

chapters                  topics
 -id                       -id
 -subject_id (fk)          -chapter_id (fk) references chapters
 -teacher_id (fk)          -parent_id (fk) references topics itself
 -title                    -title
 -designated_hours         -hours
                           -periods
                           -completion_date
                           -teaching_methodology

My question is whether my structure is normalized ? In case when topics have subtopics, the fields like hours, periods, completion_date, teaching_methodology will be null. Should I create separate table for these properties like

  topic_properties
   -id
   -topic_id (fk) references topic
   -hours
   -periods

You can also propose other database structure. I just want to make sure i get the structure right before i start this module

4

1 回答 1

1

我认为你在这里是正确的,你不需要额外的桌子。我只是做一个小的调整,以确保父子主题不能属于不同的章节:

CREATE TABLE chapters (
    chapter_id INT PRIMARY KEY
    -- (other fields)
);

CREATE TABLE topics (
    chapter_id INT,
    topic_no INT,
    parent_topic_no INT,
    -- (other fields)
    PRIMARY KEY (chapter_id, topic_no),
    FOREIGN KEY (chapter_id)
        REFERENCES chapters (chapter_id),
    FOREIGN KEY (chapter_id, parent_topic_no)
        REFERENCES topics (chapter_id, topic_no)
);

请注意第二个 FK 如何强制子行与chapter_id父行相同。

[SQL 小提琴]

于 2013-02-05T13:27:29.570 回答