Un primer enfoque muy simple sería usar solo 4 tablas:
TABLE Course
( CourseId
, Title
, TotalCredits
, ... other stuff
, PRIMARY KEY (CourseId)
) ;
TABLE Module
( ModuleId
, Description
, Hours
, Credits
, ... other stuff
, PRIMARY KEY (ModuleId)
) ;
y las combinaciones permitidas a través de estos 2:
TABLE Course_Module
( CourseID --- for this course
, ModuleID --- this module is allowed (optional or mandatory)
, PRIMARY KEY (CourseID, ModuleId)
, FOREIGN KEY (CourseId)
REFERENCES Course (CourseId)
, FOREIGN KEY (ModuleId)
REFERENCES Module (ModuleId)
) ;
TABLE Course_MandatoryModule
( CourseID --- for this course
, ModuleID --- this module is mandatory
, PRIMARY KEY (CourseID, ModuleId)
, FOREIGN KEY (CourseID, ModuleId)
REFERENCES Course_Module (CourseID, ModuleId)
) ;
Ahora, si sus combinaciones permitidas de módulos y cursos son más complicadas, como sugiere su descripción, en lugar del Course_Module
y el Course_MandatoryModule
tablas podría definir un modelo jerárquico complejo:
Cursos:
TABLE Course --- same as previous model
( CourseId
, Title
, TotalCredits
, ... other stuff
, PRIMARY KEY (CourseId)
) ;
Módulos y grupos de (módulos):
TABLE ModuleEntity --- the supertype for both
( ModuleEntityId --- modules and group of modules
, PRIMARY KEY (ModuleEntityId)
) ;
TABLE Module --- subtype
( ModuleId
, Description
, Hours
, Credits
, ... other stuff
, PRIMARY KEY (ModuleId)
, FOREIGN KEY (ModuleId)
REFERENCES ModuleEntity (ModuleEntityId)
) ;
TABLE ModuleGroup --- group of modules
( ModuleGroupId --- subtype of the supertype (entity)
, GroupDescription
, PRIMARY KEY (ModuleGroupId)
, FOREIGN KEY (ModuleGroupId)
REFERENCES ModuleEntity (ModuleEntityId)
) ;
y relación (el módulo pertenece al grupo):
TABLE Module_in_Group
( ModuleEntityId --- this module or group
, ModuleGroupId --- is in this group
, PRIMARY KEY (ModuleEntityId, ModuleGroupID)
, FOREIGN KEY (ModuleEntityId)
REFERENCES ModuleEntity (ModuleEntityId)
, FOREIGN KEY (ModuleGroupId)
REFERENCES ModuleGroup (ModuleGroupId)
) ;
y (finalmente) el curso puede tener un grupo de módulos:
TABLE Course_ModuleGroup
( CourseId --- for this course
, ModuleGroupId --- this module group is allowed
, PRIMARY KEY (CourseID, ModuleGroupId)
, FOREIGN KEY (CourseId)
REFERENCES Course (CourseId)
, FOREIGN KEY (ModuleGroupId)
REFERENCES ModuleGroup (ModuleGroupId)
) ;