这些表格很好地相互关联。我该如何解决?

时间:2013-05-30 03:57:11

标签: database sql-server-2008 entity-relationship

我有以下表格的属性:

tblCourseInstructor     CourseId int NULL,     InstructorId int NULL

并[b] tblCourses [/ B]     CourseId int IDENTITY(1,1)NOT NULL,     CourseName nvarchar(100)NULL,     CourseDescription nvarchar(2000)NULL

tblInstructors
InstructorId int NULL,     InstructorName nvarchar(50)NULL

tblLocations     LocationId int IDENTITY(1,1)NOT NULL,     位置nvarchar(50)NOT NULL,     Seating_Capacity int NULL,     offers_inclass_training位为NULL,     offers_online_training位为NULL,     Available_Seating int NULL

tblTrainingType

TrainingTypeId int IDENTITY(1,1)NOT NULL,     TrainingType nvarchar(50)NOT NULL

tblTrainingDates

DateId] int IDENTITY(1,1) NOT NULL,
trainingDates datetime NOT NULL

历史:

我们正努力在工作中创建一个培训包,员工可以在线培训课程。

这就是我们提出上述表格的原因。

有一个主表格,其中将存储注册用户及其课程选择细节。

挑战:

我们想要做的是出现课程信息屏幕。

此屏幕将要求员工从下拉列表中选择培训地点。

选择培训地点后,该地点培训的详细信息将以表格格式显示。

例如,课程名称,讲师,课程描述以及课程的日期和时间。

如果员工对此课程感兴趣,他/她将点击一个按钮注册参加此课程。

我们面临的最大挑战是将上面列出的表格绑定在一起,以便在查询表格时,我们能够列出如上所述的coursenames,教师,地点,日期和时间等。

根据我上面列出的表格,没有关键可以将所有表格捆绑在一起。

换句话说,当我们进行查询时,它们不允许以允许连接的方式相互关联。

有人可以帮助我解决我可能遗失的问题吗?

提前多多谢谢。

1 个答案:

答案 0 :(得分:0)

正如您所说,用户将首先选择位置,然后他将显示该位置的可用课程,所以

步骤 1:在Course表中有一个指向位置的键。请注意,在这种情况下,如果您在多个位置提供相同的课程,那么您需要在此表中为同一课程提供那么多记录。

tblCourses 
            CourseId int IDENTITY(1,1) NOT NULL, 
            CourseName nvarchar(100) NULL, 
            CourseDescription nvarchar(2000) NULL
            LocationId int NOT NULL, (This is FK that connects to the location table)

第2步:使用CourseId将表tblCourseInstructor连接到tblCourses。使用InstructorId将tblCourseInstructor连接到tblInstructors这些键已存在于表中。

第3步:在tblCourses中添加TrainingTypeID以连接到tblTrainingType。

tblCourses的最终结构:

tblCourses 
                CourseId int IDENTITY(1,1) NOT NULL, 
                CourseName nvarchar(100) NULL, 
                CourseDescription nvarchar(2000) NULL
                LocationId int NOT NULL, (This is FK that connects to the location table)
                TrainingTypeID  int NOT NULL  (This is FK that connects to the tblTrainingType table)

因此,基于上述关系,您可以编写所需的查询,并根据上一个下拉列表中的选项将UI中的每个下拉列表级联。