Sql-server – How To Add Days And Time For Instructor Schedule

database-designerdsql serversql-server-2008

Problem

I need to make a database design (ERD) to display a schedule for every instructor, including the following:

  • day of course (e.g. Saturday or Monday)
  • time it will give course (period from 12 PM TO 03 PM)
  • what course it will give (C# or SQL)

Example

Instructor Martin gives course C#, Monday and Saturday, for period 12 pm – 03 pm, and course SQL on Sunday and Wednesday for period 12 pm – 03 pm.

Details

I designed the following tables:

  • Instructors table (InstructorID, InstructorName)
  • Courses table (CourseID, CourseName)
  • Instructors_courses table (instcourseID, InstructorID, CourseID)

Relationship between Instructors table and Courses table is many to many so I do another table Instructors_Courses.

Questions

  1. How to represent days and times for every course added

    Can I add table for time and table for days and make relation with Instructors_courses table by adding day id and time id (one to many)

    OR do it programming from user interface.

  2. course start date and course end date these two fields how to represent in table Instructors_courses.

    I can added but it will repeated with every course are this correct or what.

Best Answer

Try making the instructor_course table like this

CREATE TABLE instructor_course (
    InstructorCourseID int IDENTITY (1,1) CONSTRAINT pk_instructor_course PRIMARY KEY CLUSTERED NOT NULL,
    DayName char(10) NOT NULL,
    CourseID int CONSTRAINT fk_CourseID_instructor_course REFERENCES Course(CourseID) NOT NULL,
    InstructorID ...
    StartTime time NOT NULL,
    EndTime time NOT NULL,
    StartDate date NOT NULL,
    EndDate date NULL);

Then you could also add some constraint to the table if you want to enforce a rule that two courses can't be timetabled at the same time. If a course has multiple sessions during the week each will be a row in this table.